Track Marker System
This track marker system allows you to create racing tracks in the Unity editor by clicking to add, edit, and delete waypoints.
How to Use
Creating a Track
- Create a TrackMarker ScriptableObject:
- Right-click in Project window
- Select Create → Race Timing → Track Markers
-
Name it (e.g., "MyTrackMarkers")
-
Add TrackMarkerManagerBehaviour to a GameObject:
- Create an empty GameObject in your scene
- Add the
TrackMarkerManagerBehaviourcomponent -
Assign your Track Markers asset to the component
-
Edit the Track in Scene View:
- Select the GameObject with TrackMarkerManagerBehaviour
- In the Scene view:
- Shift + Click on terrain/ground to add a new waypoint
- Click on an existing waypoint to select it (you can then move it with the position handle)
- Alt + Click near a waypoint to delete it
- Delete Key to remove the selected waypoint
Keyboard Controls
- Shift + Click: Add a new track marker at the clicked position
- Alt + Click: Remove the nearest track marker
- Click: Select a track marker for editing
- Delete: Remove the currently selected track marker
Visual Feedback
- Blue spheres show waypoint positions
- Light blue lines connect waypoints in sequence
- A line connects the last waypoint back to the first (forming a loop)
- Labels show "Marker 1", "Marker 2", etc.
API Reference
TrackMarkerManagerBehaviour Methods
// Get the index of the nearest waypoint to a position
int GetNearestNodeIndex(Vector3 point)
// Get the position of a waypoint by index
Vector3 NodeFromIndex(int index)
// Add a marker at the end
void AddMarker(Vector3 newPoint)
// Add a marker at a specific index
void AddMarker(int index, Vector3 newPoint)
// Remove a marker by index
void RemoveMarker(int index)
// Move an existing marker
void MoveMarker(int index, Vector3 newTargetPosition)
// Get calculated track properties
List<Vector3> trackMarkers { get; }
List<float> cumulativeDistances { get; }
float totalTrackLength { get; }