Game.Debug.RouteDebugSystem
Assembly:
Namespace: Game.Debug
Type: class
Base: BaseDebugSystem
Summary: RouteDebugSystem is a debug-only ECS system that draws gizmos for route entities and lane connections in the editor/debug view. It schedules a Burst-compiled IJobChunk (RouteGizmoJob) which iterates route-related archetype chunks and issues gizmo draw commands through a GizmosSystem.GizmoBatcher. The system exposes two toggleable debug options ("Routes" and "Lane Connections") and is disabled by default (must be enabled in the debug UI). The system depends on several components (Route, RouteWaypoint, AccessLane, RouteLane, Position, Curve, Transform, Temp, Error) to visualize waypoints, route arrows and lane connection markers.
Fields
-
private EntityQuery m_RouteGroup
This EntityQuery selects entities containing Route + RouteWaypoint or AccessLane/RouteLane (with Deleted/Hidden filtered out). The query is used to determine which chunks the RouteGizmoJob runs on and is required for the system to update. -
private GizmosSystem m_GizmosSystem
Reference to the game's GizmosSystem used to obtain a GizmoBatcher for issuing draw calls from the job. -
private Option m_RouteOption
Debug option that toggles drawing of route waypoints and connecting arrows. Default enabled in this implementation. -
private Option m_LaneConnectionOption
Debug option that toggles drawing of lane connection gizmos (access lane anchors and route-lane start/end anchors). Default enabled. -
private TypeHandle __TypeHandle
Container for cached ComponentTypeHandle / BufferTypeHandle / ComponentLookup instances used by the job. Its __AssignHandles method populates handles from a SystemState. -
(Nested)
private struct RouteGizmoJob
Burst-compiled IJobChunk that does the actual gizmo drawing. It contains read-only ComponentTypeHandle/BufferTypeHandle/ComponentLookup fields and a GizmoBatcher instance. The job decides between two modes: route visualization (Route + RouteWaypoints) and lane connection visualization (AccessLane / RouteLane, using Position or Game.Objects.Transform and Curve lookups). -
(Nested)
private struct TypeHandle
Holds ComponentTypeHandle and ComponentLookup fields and provides an __AssignHandles(ref SystemState) helper to populate them. Used to avoid repeatedly fetching type handles each update.
Properties
- None (no public properties on RouteDebugSystem)
Constructors
public RouteDebugSystem()
Default constructor. The system is attributed with [Preserve] on lifecycle methods, but the constructor itself contains no custom initialization logic beyond the base ctor.
Methods
protected override void OnCreate()
Creates/initializes system resources:- Retrieves/creates GizmosSystem.
- Builds m_RouteGroup EntityQuery (Route + RouteWaypoint and AccessLane/RouteLane alternatives, excluding Deleted/Hidden).
- Adds two debug options: "Routes" and "Lane Connections" (default enabled).
- Calls RequireForUpdate(m_RouteGroup) so the system only runs when matching entities exist.
-
Disables the system by default (base.Enabled = false). Notes: Marked with [Preserve].
-
protected override JobHandle OnUpdate(JobHandle inputDeps)
Schedules the Burst RouteGizmoJob using JobChunkExtensions.ScheduleParallel over m_RouteGroup. Before scheduling it: - Fills the job struct fields (option flags, component type handles via InternalCompilerInterface.GetComponentTypeHandle / GetBufferTypeHandle, component lookups, and obtains a GizmosBatcher from m_GizmosSystem).
- Combines dependencies with the GizmosSystem's returned dependency.
-
Registers the returned job handle with m_GizmosSystem via AddGizmosBatcherWriter(jobHandle). Returns the scheduled JobHandle.
-
private void __AssignQueries(ref SystemState state)
Internal helper invoked by the compiler-time OnCreateForCompiler. In this implementation it creates and immediately disposes an EntityQueryBuilder(Allocator.Temp) — placeholder used by generated code to ensure query layout is recorded. -
protected override void OnCreateForCompiler()
Compiler helper called to initialize TypeHandle and other query-related state when compiling systems ahead-of-time. Calls __AssignQueries and __TypeHandle.__AssignHandles. -
(Nested TypeHandle)
public void __AssignHandles(ref SystemState state)
Populates the TypeHandle's ComponentTypeHandle, BufferTypeHandle and ComponentLookup fields by calling state.GetComponentTypeHandle(isReadOnly: true), GetBufferTypeHandle , and GetComponentLookup (isReadOnly: true). This prepares the handles used by the RouteGizmoJob. -
(Nested RouteGizmoJob)
public void Execute(in ArchetypeChunk chunk, int unfilteredChunkIndex, bool useEnabledMask, in v128 chunkEnabledMask)
Core job execution: - Chooses color based on whether the chunk has Error (red), Temp flag absent (cyan) or Temp present (blue).
- If the chunk contains Route components and the Route option is enabled:
- Iterate Route buffers (RouteWaypoint) and draw wire nodes at each waypoint position (via Position lookup).
- Draw middle arrow lines between consecutive waypoints; if route is complete it connects last->first.
- Else if lane-connection mode is active and lane option enabled:
- Uses either Position or Game.Objects.Transform for the entity anchor position (depending on which exists in chunk).
- For each AccessLane: if corresponding Curve component exists, compute Bezier position and draw a small green node and a line to the entity anchor.
- For each RouteLane: if start/end lanes have Curve components, compute Bezier positions and draw magenta nodes and lines to the entity anchor.
- The job uses ComponentLookup
and ComponentLookup to read external components (curve bezier data and waypoint positions). This method is also exposed via the explicit IJobChunk.Execute implementation.
Usage Example
[Preserve]
protected override void OnCreate()
{
base.OnCreate();
// Typical initialization already present in RouteDebugSystem:
// - Get or create the GizmosSystem
// - Register the entity query
// - Add debug options for "Routes" and "Lane Connections"
// The system is disabled by default; enable it via the debug UI or by setting:
// this.Enabled = true;
m_GizmosSystem = World.GetOrCreateSystemManaged<GizmosSystem>();
m_RouteOption = AddOption("Routes", defaultEnabled: true);
m_LaneConnectionOption = AddOption("Lane Connections", defaultEnabled: true);
RequireForUpdate(m_RouteGroup);
this.Enabled = true; // enable live drawing
}
Additional notes: - The system is intended for debugging and visualization; it runs on the DOTS ECS side and uses Burst for performance. - Ensure the relevant components (Route, RouteWaypoint, AccessLane, RouteLane, Position, Curve, Transform) exist in your world to see gizmos. - The gizmo drawing is batched by GizmosSystem.GizmoBatcher; RouteGizmoJob obtains a batcher and registers its job dependency with the GizmosSystem to safely write draw commands from jobs.