Skip to content

Game.Prefabs.SpawnLocation

Assembly: Assembly-CSharp
Namespace: Game.Prefabs

Type: public class

Base: ComponentBase

Summary:
Prefab component used to define a spawn location for routed objects/agents. This component exposes configuration for the route connection type (e.g., pedestrian, air), allowed track and road types, and flags such as whether authorization is required and whether spawned agents should hang around on a lane. At prefab build time it contributes ECS components to the entity archetype (SpawnLocationData and, for air connections, TakeoffLocation) and at initialization it writes a SpawnLocationData instance into the entity. This class is used when authoring object prefabs for Cities: Skylines 2 modding to control how and where agents/vehicles spawn and connect to route networks.


Fields

  • public RouteConnectionType m_ConnectionType = RouteConnectionType.Pedestrian
    Specifies the connection type for this spawn location (for example Pedestrian, Vehicle, Air). Controls route matching and, in GetArchetypeComponents, will add a Game.Routes.TakeoffLocation component when set to Air.

  • public TrackTypes m_TrackTypes
    Allowed track types (likely a flags enum) for this spawn location. Used to restrict which rail/track-based routes can use this spawn point.

  • public RoadTypes m_RoadTypes
    Allowed road types (likely a flags enum) for this spawn location. Used to restrict which road-based routes can use this spawn point.

  • public bool m_RequireAuthorization
    If true, the spawn location requires authorization for agents/vehicles to use it. Meaning depends on route/ownership/security systems in the game.

  • public bool m_HangaroundOnLane
    If true, spawned agents may wait/hang around on the lane instead of immediately leaving the spawn location. Controls spawn behavior for queuing or waiting.

Properties

  • This class does not declare public C# properties. It exposes public fields (see Fields).

Constructors

  • public SpawnLocation()
    Default constructor (compiler-provided). Field defaults: m_ConnectionType defaults to RouteConnectionType.Pedestrian; other fields use their default values (uninitialized enums/booleans default to 0/false). Unity/serialization will normally populate these fields from prefab data.

Methods

  • public override void GetPrefabComponents(HashSet<ComponentType> components)
    Adds the runtime component types this prefab requires when creating entities from the prefab. Implementation adds ComponentType.ReadWrite(), ensuring the ECS entity will have a SpawnLocationData component.

  • public override void GetArchetypeComponents(HashSet<ComponentType> components)
    Adds archetype component types based on configuration. Always adds ComponentType.ReadWrite(). If m_ConnectionType == RouteConnectionType.Air, also adds ComponentType.ReadWrite(). This lets the entity archetype include takeoff-specific data when the spawn is for air vehicles.

  • public override void Initialize(EntityManager entityManager, Entity entity)
    Called when the prefab entity is created/initialized. Builds a SpawnLocationData struct, populates its fields from the prefab's serializable fields (m_ConnectionType, m_TrackTypes, m_RoadTypes, m_RequireAuthorization, m_HangaroundOnLane) and sets it on the entity via EntityManager.SetComponentData(entity, componentData). Also initializes the ActivityMask to its default value.

Notes: - Depends on types SpawnLocationData (Game.Objects.SpawnLocationData / Game.Objects.SpawnLocation), Game.Routes.TakeoffLocation, ActivityMask and Unity.Entities API (ComponentType, EntityManager, Entity). - This class is designed for use during prefab authoring; the actual runtime behavior of spawned agents is controlled by the systems that read SpawnLocationData.

Usage Example

// Typical Initialize implementation (same behavior as in SpawnLocation.cs)
public override void Initialize(EntityManager entityManager, Entity entity)
{
    base.Initialize(entityManager, entity);

    SpawnLocationData componentData = default;
    componentData.m_ConnectionType = m_ConnectionType;
    componentData.m_ActivityMask = default(ActivityMask);
    componentData.m_TrackTypes = m_TrackTypes;
    componentData.m_RoadTypes = m_RoadTypes;
    componentData.m_RequireAuthorization = m_RequireAuthorization;
    componentData.m_HangaroundOnLane = m_HangaroundOnLane;

    entityManager.SetComponentData(entity, componentData);
}

Additional tips: - If you set m_ConnectionType to RouteConnectionType.Air, ensure any necessary takeoff-related components/data are provided by the prefab or systems that handle air routes. - TrackTypes and RoadTypes are typically flags enums — set them to match the transport types you want the spawn location to accept. - Use m_RequireAuthorization to gate access for special spawn locations (e.g., restricted areas, vehicle depots).