Skip to content

Game.Prefabs.ActivityLocation

Assembly: Assembly-CSharp
Namespace: Game.Prefabs

Type: class

Base: ComponentBase

Summary:
ActivityLocation is a prefab component used to define one or more activity spawn points (locations where Activity prefabs are instantiated/used) tied to a prefab (static object, marker, vehicle prefab, etc.). It declares a set of LocationInfo entries describing the activity prefab, local position and rotation, optional animated prop name to attach, and optionally whether the location requires authorization. During LateInitialize it populates ECS buffers/components (ActivityLocationElement, SpawnLocationData, Game.Objects.SpawnLocation/Game.Objects.ActivityLocation archetype components) and aggregates activity masks from the referenced Activity prefabs. It also maps NetInvertMode to ActivityFlags to support inverted-traffic variants.


Fields

  • public class LocationInfo
    Nested serializable helper class that describes a single activity spawn location.
  • public ActivityLocationPrefab m_Activity — reference to the Activity prefab used at this location.
  • public float3 m_Position — local position (float3) of the activity relative to the prefab origin.
  • public quaternion m_Rotation — local rotation (quaternion) of the activity.

  • public LocationInfo[] m_Locations
    Array of LocationInfo entries. Each entry becomes an ActivityLocationElement in the prefab's dynamic buffer during LateInitialize. If null or empty, LateInitialize logs an error.

  • public NetInvertMode m_InvertWhen
    Controls when the activity should use inverted variants (lefthand, righthand or always). Mapped to ActivityFlags.InvertLefthandTraffic and/or ActivityFlags.InvertRighthandTraffic in the created ActivityLocationElement entries.

  • public string m_AnimatedPropName
    Name used to look up an AnimatedPropID via the AnimatedSystem. The resolved prop ID is stored in ActivityLocationElement.m_PropID so the activity can show/use the animated prop (e.g., a bench, sign).

  • public bool m_RequireAuthorization
    If true, sets SpawnLocationData.m_RequireAuthorization so the spawn/location requires authorization.

Properties

  • public override bool ignoreUnlockDependencies { get }
    Always returns true in this component. Means this component ignores prefab unlock dependencies (prefab will not be blocked by unlock checks implemented in the base dependency system).

Constructors

  • public ActivityLocation()
    Default parameterless constructor (implicit). The component is typically configured in the prefab asset rather than constructed in code at runtime.

Methods

  • public override void GetDependencies(List<PrefabBase> prefabs)
    Adds referenced Activity prefabs (m_Locations[i].m_Activity) to the provided prefabs list so the prefab system knows about dependent prefabs. Calls base.GetDependencies(prefabs) first.

  • public override void GetPrefabComponents(HashSet<ComponentType> components)
    Adds runtime component types required on the prefab entity:

  • Adds SpawnLocationData (read/write) unless the base.prefab is a VehiclePrefab or BuildingPrefab.
  • Adds ActivityLocationElement (read/write) always. This prepares the prefab entity's component set for the data filled in LateInitialize.

  • public override void GetArchetypeComponents(HashSet<ComponentType> components)
    Adds archetype component types for the entity archetype:

  • Adds Game.Objects.SpawnLocation and Game.Objects.ActivityLocation (read/write) unless the base.prefab is a VehiclePrefab or BuildingPrefab. These are the concrete ECS data components used by gameplay systems.

  • public override void LateInitialize(EntityManager entityManager, Entity entity)
    Main initialization logic run when the prefab is converted to an entity. Behavior:

  • Calls base.LateInitialize(entityManager, entity).
  • Prepares a SpawnLocationData with defaults:
    • m_ConnectionType = RouteConnectionType.Pedestrian
    • m_ActivityMask = empty then aggregated with referenced activities
    • m_RoadTypes / m_TrackTypes = None
    • m_RequireAuthorization = m_RequireAuthorization
    • m_HangaroundOnLane = false
  • If m_Locations is non-null and non-empty:
    • Resizes the entity's DynamicBuffer to m_Locations.Length.
    • Resolves the referenced activity prefabs to entities via PrefabSystem.GetEntity().
    • Resolves the animated prop ID via AnimatedSystem.GetPropID(m_AnimatedPropName).
    • For each LocationInfo:
    • Creates an ActivityLocationElement setting m_Prefab (entity), m_Position, m_Rotation, m_PropID.
    • Maps m_InvertWhen to ActivityFlags (InvertLefthandTraffic and/or InvertRighthandTraffic).
    • Reads ActivityLocationData from the activity prefab entity to copy its activity mask into the element and ORs it into the SpawnLocationData.m_ActivityMask.
    • Writes the element into the buffer.
  • If m_Locations is null or empty, logs an error through ComponentBase.baseLog.
  • If base.prefab is not VehiclePrefab or BuildingPrefab, writes the constructed SpawnLocationData to the entity (entityManager.SetComponentData).
  • Depends on PrefabSystem and AnimatedSystem existing on the world (used to resolve prefab entities and prop IDs).

Notes / edge cases: - VehiclePrefab and BuildingPrefab are treated specially: SpawnLocationData and certain archetype components are not added/assigned for them. - Activity mask aggregation ensures the prefab reports all activities its locations provide.

Usage Example

// Example: configure an ActivityLocation in code (normally serialized in a prefab asset)
var activityLocation = new ActivityLocation();
activityLocation.m_AnimatedPropName = "BenchProp";
activityLocation.m_InvertWhen = NetInvertMode.RighthandTraffic;
activityLocation.m_RequireAuthorization = false;

activityLocation.m_Locations = new ActivityLocation.LocationInfo[]
{
    new ActivityLocation.LocationInfo
    {
        m_Activity = someActivityPrefab, // ActivityLocationPrefab reference
        m_Position = new float3(0f, 0.0f, 0f),
        m_Rotation = quaternion.EulerXYZ(new float3(0f, math.PI * 0.5f, 0f))
    }
};

// The prefab system will call LateInitialize(...) during conversion to an entity, resolving
// the animation prop ID and the activity prefab entity, and filling the ActivityLocationElement buffer.