Game.Prefabs.CarPathfind
Assembly: Assembly-CSharp
Namespace: Game.Prefabs
Type: class
Base: ComponentBase
Summary:
CarPathfind is a prefab component that encapsulates configurable pathfinding cost parameters for cars. It exposes several PathfindCostInfo fields (driving, turning, U-turns, parking, etc.) that are converted and written into the ECS component PathfindCarData when the prefab is initialized. This component is used by the game's pathfinding systems to influence route selection and penalties for various maneuvers.
Fields
-
public PathfindCostInfo m_DrivingCost
Default: new PathfindCostInfo(0f, 0f, 0.01f, 0f)
Holds cost parameters used for normal driving travel. Converted to internal PathfindCarData.m_DrivingCost during Initialize(). -
public PathfindCostInfo m_TurningCost
Default: new PathfindCostInfo(0f, 0f, 0f, 1f)
Cost parameters applied when making turns. -
public PathfindCostInfo m_UTurnCost
Default: new PathfindCostInfo(0f, 0f, 0f, 10f)
Cost parameters for safe U-turn maneuvers. -
public PathfindCostInfo m_UnsafeUTurnCost
Default: new PathfindCostInfo(0f, 50f, 0f, 10f)
Cost parameters for U-turns flagged as unsafe (higher penalty). -
public PathfindCostInfo m_CurveAngleCost
Default: new PathfindCostInfo(2f, 0f, 0f, 3f)
Costs influenced by curve angles (penalizes sharp curves/angles). -
public PathfindCostInfo m_LaneCrossCost
Default: new PathfindCostInfo(0f, 0f, 0f, 2f)
Costs applied for lane changes / crossing lanes. -
public PathfindCostInfo m_ParkingCost
Default: new PathfindCostInfo(10f, 0f, 0f, 0f)
Penalty/weight applied when considering parking maneuvers. -
public PathfindCostInfo m_SpawnCost
Default: new PathfindCostInfo(5f, 0f, 0f, 0f)
Cost applied at spawn points or when entering the network. -
public PathfindCostInfo m_ForbiddenCost
Default: new PathfindCostInfo(10f, 100f, 20f, 50f)
High penalties used for forbidden or strongly discouraged moves/areas.
Properties
- This class does not declare any C# properties. It exposes configurable public fields (PathfindCostInfo) that are used during initialization.
Constructors
public CarPathfind()
The default constructor is implicit. Field initializers establish default PathfindCostInfo values shown above. In typical use the prefab/component instance is configured in the editor (or by code) before Initialize is called by the prefab system.
Methods
-
public override void GetPrefabComponents(HashSet<ComponentType> components)
Ensures the ECS entity for this prefab has a PathfindCarData component by adding ComponentType.ReadWrite() to the provided set. This tells the prefab/ECS system which component type is required for entities created from this prefab. -
public override void GetArchetypeComponents(HashSet<ComponentType> components)
Empty override. No additional archetype components are declared here. -
public override void Initialize(EntityManager entityManager, Entity entity)
Called when the prefab is instantiated into an ECS entity. Converts each PathfindCostInfo field to its internal representation by calling ToPathfindCosts() and writes the resulting values into a new PathfindCarData struct on the entity via entityManager.SetComponentData(...). This is the key method that transfers the editable prefab settings into runtime ECS data used by pathfinding.
Usage Example
// Example: After a CarPathfind prefab has been applied to an entity by the prefab system,
// its Initialize method will populate the PathfindCarData component on that entity.
// You can then read the converted PathfindCarData from the EntityManager:
// assume entityManager and entity refer to the created entity with this prefab
PathfindCarData carData = entityManager.GetComponentData<PathfindCarData>(entity);
// carData now contains fields such as m_DrivingCost, m_TurningCost, etc.
// (structure names/fields are internal; inspect PathfindCarData to access specific members)
Additional notes: - PathfindCostInfo.ToPathfindCosts() is used to convert designer-friendly cost settings into the internal PathfindCosts representation consumed by the pathfinding systems. - Adjusting these values in the prefab allows modders to tweak vehicle routing behavior without touching the pathfinding systems directly.