Game.Prefabs.PedestrianPathfind
Assembly:
Namespace: Game.Prefabs
Type: class
Base: ComponentBase
Summary:
PedestrianPathfind is a prefab component that defines pathfinding cost parameters for pedestrian routing. It exposes a set of PathfindCostInfo fields (walking, crosswalk, unsafe crosswalk, and spawn costs) which are converted and stored into a PathfindPedestrianData component on the ECS entity when Initialize is called. The class is annotated with a ComponentMenu attribute so it can be used as a prefab under the "Pathfind/" menu and is intended for use in modding Cities: Skylines 2 to tune pedestrian path selection behavior.
Fields
-
public PathfindCostInfo m_WalkingCost
Default: new PathfindCostInfo(0f, 0f, 0f, 0.01f)
Defines the base cost settings used for normal walking segments. Values are stored as a PathfindCostInfo and converted to the ECS PathfindPedestrianData on initialization. -
public PathfindCostInfo m_CrosswalkCost
Default: new PathfindCostInfo(0f, 0f, 0f, 5f)
Cost parameters used for crosswalk segments. Higher values typically make crosswalks less preferred; tune these to influence pedestrian route selection. -
public PathfindCostInfo m_UnsafeCrosswalkCost
Default: new PathfindCostInfo(0f, 100f, 0f, 5f)
Cost parameters used for crosswalks marked as unsafe (for example, lacking traffic control). The defaults reflect a strong penalty (100f in one of the components) to discourage use. -
public PathfindCostInfo m_SpawnCost
Default: new PathfindCostInfo(5f, 0f, 0f, 0f)
Costs applied when spawning pedestrians; influences starting location selection or initial steps in pathfinding.
Properties
- None declared on this type. (All relevant data is provided via public fields and converted to a PathfindPedestrianData component.)
Constructors
public PedestrianPathfind()
No explicit constructor is defined in the source; the class uses the default parameterless constructor inherited/auto-provided by the runtime. Fields are initialized with their inline defaults as shown above.
Methods
-
public override void GetPrefabComponents(HashSet<ComponentType> components)
AddsComponentType.ReadWrite<PathfindPedestrianData>()
to the provided set. This tells the prefab system / ECS that entities using this prefab require a PathfindPedestrianData component (read-write). -
public override void GetArchetypeComponents(HashSet<ComponentType> components)
Empty override. No additional archetype components are contributed by this prefab beyond what GetPrefabComponents supplies. -
public override void Initialize(EntityManager entityManager, Entity entity)
Called to initialize the ECS entity for this prefab. This method converts each PathfindCostInfo field to the internal pathfinding cost representation using ToPathfindCosts() and sets a PathfindPedestrianData component on the given entity via entityManager.SetComponentData(...). This is the critical step that transfers editable prefab values into runtime ECS component data that pathfinding systems will read.
Usage Example
// Create/configure a PedestrianPathfind prefab in code (typically prefabs are configured in editor)
var pedPathfind = new PedestrianPathfind();
pedPathfind.m_WalkingCost = new PathfindCostInfo(0f, 0f, 0f, 0.02f);
pedPathfind.m_CrosswalkCost = new PathfindCostInfo(0f, 10f, 0f, 5f);
// When the prefab system initializes the entity, Initialize will be called.
// Example: manually initializing for an entity (normally done by the engine prefab loader)
EntityManager em = /* obtain EntityManager */;
Entity entity = /* create or obtain an Entity for this prefab */;
pedPathfind.Initialize(em, entity);
// The entity now has a PathfindPedestrianData component containing the converted costs,
// which the game's pedestrian pathfinding systems will use.