Game.Prefabs.TrackPathfind
Assembly: Assembly-CSharp
Namespace: Game.Prefabs
Type: class
Base: ComponentBase
Summary:
TrackPathfind is a prefab component that supplies pathfinding cost configuration for track (rail/track-like) prefabs. It exposes several PathfindCostInfo fields that are converted into a PathfindTrackData ECS component during prefab initialization. This data is used by the game's pathfinding systems to influence route selection and penalties for switches, crossings, curves, spawns, etc.
Fields
-
public PathfindCostInfo m_DrivingCost = new PathfindCostInfo(0f, 0f, 0.01f, 0f)
This PathfindCostInfo represents the base driving cost for the track. The default instance is created inline. The meaning of the individual float parameters is defined by PathfindCostInfo (see its documentation); TrackPathfind simply stores the configuration used to build the runtime PathfindTrackData. -
public PathfindCostInfo m_TwowayCost = new PathfindCostInfo(0f, 0f, 0f, 5f)
Cost configuration applied for two-way track segments. Default values are provided inline. -
public PathfindCostInfo m_SwitchCost = new PathfindCostInfo(0f, 0f, 0f, 2f)
Cost configuration for switch (track junction) tiles or elements. Defaults penalize switches according to the provided values. -
public PathfindCostInfo m_DiamondCrossingCost = new PathfindCostInfo(0f, 0f, 0f, 2f)
Cost configuration applied to diamond crossings / level crossings between tracks. -
public PathfindCostInfo m_CurveAngleCost = new PathfindCostInfo(2f, 0f, 0f, 3f)
Cost configuration for curves; defaults include a non-zero value (2f) in the first parameter and a curve penalty (3f in the last param) to penalize sharper angles. -
public PathfindCostInfo m_SpawnCost = new PathfindCostInfo(5f, 0f, 0f, 0f)
Cost configuration applied when spawning vehicles onto the track; defaults include a higher spawn cost (5f) in the first parameter.
Properties
- (none)
This prefab component does not expose public C# properties. Configuration is provided through the public fields above.
Constructors
public TrackPathfind()
Default constructor (implicit). All PathfindCostInfo fields are initialized inline with the default values shown in the field declarations.
Methods
-
public override void GetPrefabComponents(HashSet<ComponentType> components)
Adds the runtime ECS component types required by this prefab. Implementation: callscomponents.Add(ComponentType.ReadWrite<PathfindTrackData>());
— ensuring that entity instances of this prefab include a writable PathfindTrackData component so pathfinding systems can read the configured costs at runtime. -
public override void GetArchetypeComponents(HashSet<ComponentType> components)
Empty override. This method intentionally adds no archetype-only components for this prefab. -
public override void Initialize(EntityManager entityManager, Entity entity)
Called when the prefab is instantiated into the ECS world. This method sets the PathfindTrackData component on the entity using the stored PathfindCostInfo fields converted viaToPathfindCosts()
: - m_DrivingCost -> m_DrivingCost
- m_TwowayCost -> m_TwowayCost
- m_SwitchCost -> m_SwitchCost
- m_DiamondCrossingCost -> m_DiamondCrossingCost
- m_CurveAngleCost -> m_CurveAngleCost
- m_SpawnCost -> m_SpawnCost This populates the entity's pathfinding cost data so pathfinding jobs/systems can use the configured penalties and weights.
Usage Example
// Example: manually initializing the prefab component for an entity.
// In the real modding pipeline this is done by the prefab system when a prefab is created.
// This demonstrates how the TrackPathfind populates the ECS component PathfindTrackData.
var entityManager = World.DefaultGameObjectInjectionWorld.EntityManager;
Entity entity = entityManager.CreateEntity();
// Create TrackPathfind and optionally adjust defaults before initialization
var trackPathfind = new Game.Prefabs.TrackPathfind();
// Example: tweak a cost before applying (optional)
// trackPathfind.m_CurveAngleCost = new PathfindCostInfo(3f, 0f, 0f, 4f);
// Initialize will write the PathfindTrackData component to the entity
trackPathfind.Initialize(entityManager, entity);
// After Initialize, the entity has a PathfindTrackData component populated from the PathfindCostInfo values.
Notes and Modding Tips: - The numeric parameters for PathfindCostInfo are defined by the PathfindCostInfo type — consult its documentation to know what each parameter represents (e.g., base weight, penalties, angle multipliers, etc.). - Changes to TrackPathfind field defaults require prefab reloading or rebuilding to take effect on existing entities. - This component is designed to work with Unity.Entities (ECS). Ensure your code runs at an appropriate time and thread context when interacting with EntityManager and entity components.