Game.Simulation.VehicleLaunchSystem
Assembly: Assembly-CSharp
Namespace: Game.Simulation
Type: class
Base: GameSystemBase
Summary:
VehicleLaunchSystem is a simulation system that processes Game.Events.VehicleLaunch events. It performs two main responsibilities:
- When an event requests a path (PathRequested flag not set), it enqueues pathfinding work for a produced vehicle (typically rockets) owned by the event's spectator site, sets up PathInformation and PathElement buffer components on the event entity, and marks the event as having requested a path.
- When the path is ready and the event has not yet launched the vehicle (Launched flag not set), it transfers path data and launch state from the event to the produced vehicle: removes the Produced component, sets Target, PathOwner, and PublicTransport state on the vehicle, copies path elements to the vehicle, and marks the event as launched.
The system runs at an interval of 64 simulation frames, uses a Burst-compiled IJobChunk (VehicleLaunchJob) to operate in parallel, and uses EndFrameBarrier to create a parallel command buffer for structural changes. It also uses PathfindSetupSystem to enqueue pathfinding work.
Fields
-
private const uint UPDATE_INTERVAL = 64u
Defines the update interval (in simulation frames). The system requests updates every 64 frames. -
private SimulationSystem m_SimulationSystem
Reference to the SimulationSystem used to read the current simulation frame (frameIndex) for time gating VehicleLaunch events. -
private PathfindSetupSystem m_PathfindSetupSystem
Reference to the PathfindSetupSystem used to obtain a pathfinding queue writer where path setup work is enqueued. -
private EndFrameBarrier m_EndFrameBarrier
Reference to the EndFrameBarrier used to create an EntityCommandBuffer.ParallelWriter to perform structural changes at end of frame safely. -
private EntityQuery m_LaunchQuery
EntityQuery selecting entities with Game.Events.VehicleLaunch (read/write) and excluding Deleted and Temp so the job runs on relevant event entities. -
private TypeHandle __TypeHandle
Internal generated struct that stores EntityTypeHandle, ComponentTypeHandle and BufferTypeHandle instances. Used to obtain handles for the job scheduling.
Properties
- None specific to this class (no public properties exposed).
Constructors
public VehicleLaunchSystem()
Default constructor. The system is [Preserve] attributed for runtime compatibility. Initialization of references happens in OnCreate.
Methods
-
public override int GetUpdateInterval(SystemUpdatePhase phase)
Returns the update interval (64). Used by the system scheduler to reduce update frequency. -
[Preserve] protected override void OnCreate()
Sets up the system: acquires references to SimulationSystem, PathfindSetupSystem and EndFrameBarrier from the World, constructs the m_LaunchQuery (VehicleLaunch components excluding Deleted and Temp), and calls RequireForUpdate to ensure the system runs only when such entities exist. -
[Preserve] protected override void OnUpdate()
Creates and populates the VehicleLaunchJob (Burst compiled IJobChunk) with: - Current simulation frame from SimulationSystem.
- A ParallelWriter command buffer from EndFrameBarrier for structural/component changes.
- A ParallelWriter queue for pathfinding setup from PathfindSetupSystem.
-
Component/Buffer/Lookup handles obtained via the internal TypeHandle. Schedules the job in parallel over m_LaunchQuery, sets base.Dependency to the returned JobHandle, adds the producer handle to EndFrameBarrier (so the ECB will play back after the job), and notifies PathfindSetupSystem that a queue writer is in use.
-
private void __AssignQueries(ref SystemState state)
Compiler-generated helper that currently only creates and disposes an EntityQueryBuilder (placeholder; used by generated code paths). -
protected override void OnCreateForCompiler()
Compiler-time initialization helper: assigns queries and component handles by invoking __AssignQueries and TypeHandle.__AssignHandles. Called by generated code paths.
Inner type: VehicleLaunchJob (BurstCompile) — nested private struct implementing IJobChunk used to process VehicleLaunch events in parallel.
- VehicleLaunchJob.Execute(in ArchetypeChunk chunk, int unfilteredChunkIndex, bool useEnabledMask, in v128 chunkEnabledMask)
Main chunk-processing method. For each event entity in the chunk: - Reads VehicleLaunch event, PrefabRef, Duration (when present) and target buffer.
- If VehicleLaunchFlags.PathRequested is not set:
- If a Duration exists and event start frame is in the future, it skips the event until the start frame.
- Finds the spectator site entity referenced in the event's TargetElement buffer.
- Finds a produced vehicle owned by that site (searches OwnedVehicle buffer and checks for Produced component).
- Reads VehicleLaunchData from the prefab referenced by PrefabRef.
- If a produced vehicle exists and the transport type is Rocket, it builds PathfindParameters and SetupQueueTargets (origin current location and destination outside connection with value2 = 1000f), configures path methods and road types for rocket (Road|Flying, helicopter road type indicators), and enqueues a SetupQueueItem in the PathfindSetupSystem queue.
- Regardless, it adds a PathInformation component and a PathElement buffer to the event entity via the command buffer, and sets the PathRequested flag on the event.
- Else if VehicleLaunchFlags.PathRequested is set and VehicleLaunchFlags.Launched is not set:
- Finds the spectator site and produced vehicle as above.
- If produced vehicle exists and PathInformation and PathElement buffer exist on the event, it:
- Removes Produced component from the vehicle.
- Sets Target on the vehicle to the destination stored in PathInformation.
- Sets PathOwner on the vehicle with PathFlags.Updated.
- Sets PublicTransport.m_State = PublicTransportFlags.Launched on the vehicle.
- Copies PathElement buffer from event to vehicle using command buffer's SetBuffer and PathUtils.CopyPath.
- Marks the event as Launched.
-
Writes back the updated VehicleLaunch event component.
-
VehicleLaunchJob.FindSpectatorSite(DynamicBuffer
targetElements, Entity eventEntity) : Entity
Iterates the event's target elements, returning the entity that has SpectatorSite component whose m_Event equals the provided event entity. Returns Entity.Null if none found. -
VehicleLaunchJob.FindProducedVehicle(Entity siteEntity) : Entity
Checks the OwnedVehicle buffer on the site entity and returns the first vehicle entity that has a Produced component. Returns Entity.Null if none found. -
VehicleLaunchJob.FindPath(int jobIndex, Entity eventEntity, Entity vehicleEntity, VehicleLaunchData vehicleLaunchData)
If vehicleEntity is valid, configures PathfindParameters (max speed, walk speed, weights, ignored rules) and SetupQueueTarget origin/destination. For TransportType.Rocket it sets methods and road/flying types appropriate for rocket launches and enqueues a SetupQueueItem to the PathfindSetupSystem queue. Adds PathInformation component and PathElement buffer to the event entity via command buffer for storing result. -
VehicleLaunchJob.LaunchVehicle(int jobIndex, Entity eventEntity, Entity vehicleEntity)
Transfers path and launch state from the event to the vehicle: - Removes Produced from vehicle.
- Sets Target to event's PathInformation.m_Destination.
- Sets PathOwner with PathFlags.Updated.
- Sets Game.Vehicles.PublicTransport.m_State to Launched.
- Copies PathElement buffer from event to vehicle via PathUtils.CopyPath.
Notes about components and types used: - Game.Events.VehicleLaunch: event component containing launch flags (VehicleLaunchFlags.PathRequested, VehicleLaunchFlags.Launched). - PrefabRef: used to look up VehicleLaunchData for transport type. - VehicleLaunchData: prefab data that indicates TransportType (e.g., Rocket). - PathInformation, PathElement: components/buffer used to hold pathfinding results on the event entity (created by this system before path setup completes). - OwnedVehicle buffer on spectator site entities: lists vehicles owned by a site; Produced component indicates a vehicle produced/available to be launched. - Produced: marker component that denotes vehicle is produced and awaiting deployment. - PathfindSetupSystem queue: receives SetupQueueItem entries to schedule pathfinding. - EndFrameBarrier: used to play back command buffer safely at frame end.
Usage Example
// Typical usage inside a mod initializer to ensure the system exists and runs:
var world = World.DefaultGameObjectInjectionWorld;
var vehicleLaunchSystem = world.GetOrCreateSystemManaged<Game.Simulation.VehicleLaunchSystem>();
// The system runs automatically. The system will:
// - Enqueue pathfinding for VehicleLaunch events (every 64 frames).
// - When a path is ready, transfer path and launch the produced vehicle.
If you need a small snippet showing how the system schedules the job in OnUpdate, here's the relevant pattern (simplified):
protected override void OnUpdate()
{
var jobData = new VehicleLaunchJob {
m_SimulationFrame = m_SimulationSystem.frameIndex,
m_CommandBuffer = m_EndFrameBarrier.CreateCommandBuffer().AsParallelWriter(),
m_PathfindQueue = m_PathfindSetupSystem.GetQueue(this, 64).AsParallelWriter(),
// component/buffer lookups filled from internal handles...
};
base.Dependency = JobChunkExtensions.ScheduleParallel(jobData, m_LaunchQuery, base.Dependency);
m_EndFrameBarrier.AddJobHandleForProducer(base.Dependency);
m_PathfindSetupSystem.AddQueueWriter(base.Dependency);
}
If you want, I can also produce a breakdown of the VehicleLaunchJob fields and the exact component types used (signatures for PathfindParameters, SetupQueueItem, PathUtils.CopyPath usage, etc.) to assist with writing compatible code in mods.