Skip to content

Game.Creatures.HumanCurrentLane

Assembly: Game
Namespace: Game.Creatures

Type: struct

Base: IComponentData, IQueryTypeParameter, ISerializable

Summary:
HumanCurrentLane is a component used by creature (human) entities to track their current lane and queue-related state while navigating the road/lane network. It stores references to the lane entity and any queue entity, geometric/curve position data used for lane-following, lane-related flags, and a scalar lane position. It also implements custom binary serialization/deserialization used by the game's save/load system and supports version-aware reading of the lane position field.


Fields

  • public Entity m_Lane
    Holds the Entity representing the lane (target lane) the creature is currently using. Can be Entity.Null when not assigned.

  • public Entity m_QueueEntity
    Entity of a queue object associated with this lane (for example a waiting queue). Defaults to Entity.Null when no queue is present.

  • public Sphere3 m_QueueArea
    Defines the 3D spherical area of the queue. Uses Colossal.Mathematics.Sphere3. Default-initialized when no queue area is set.

  • public float2 m_CurvePosition
    Curve position on the lane used for lane-following / path sampling. Usually initialized from an AccessLane or PathElement (accessLane.m_CurvePos or pathElement.m_TargetDelta.xx).

  • public CreatureLaneFlags m_Flags
    Bitflags describing lane state/behavior for the creature (type defined elsewhere).

  • public float m_LanePosition
    Scalar position along the lane (float). This field is versioned in serialization — older save versions may not contain it and it will remain default (0) when deserialized from such saves.

Properties

  • This struct exposes no C# properties; all data is held in public fields for direct ECS access.

Constructors

  • public HumanCurrentLane(AccessLane accessLane, CreatureLaneFlags flags)
    Initializes a HumanCurrentLane from an AccessLane. Sets m_Lane to accessLane.m_Lane, m_CurvePosition to accessLane.m_CurvePos, m_Flags to flags, and other fields to defaults (null/0).

  • public HumanCurrentLane(PathElement pathElement, CreatureLaneFlags flags)
    Initializes from a PathElement. Sets m_Lane to pathElement.m_Target, m_CurvePosition to pathElement.m_TargetDelta.xx, m_Flags to flags, other fields defaulted.

  • public HumanCurrentLane(CreatureLaneFlags flags)
    Initializes an empty/invalid lane with only flags set. m_Lane and m_QueueEntity are set to Entity.Null, m_CurvePosition & m_QueueArea defaulted, and m_LanePosition set to 0.

Methods

  • public void Serialize<TWriter>(TWriter writer) where TWriter : IWriter
    Writes the component fields to the provided writer in binary form. The implementation writes:
  • m_Lane (Entity)
  • m_CurvePosition (float2)
  • m_Flags cast to uint
  • m_LanePosition (float) The order matters for matching deserialization.

  • public void Deserialize<TReader>(TReader reader) where TReader : IReader
    Reads the component fields from the provided reader. Behavior details:

  • Reads m_Lane (Entity)
  • Reads m_CurvePosition (float2)
  • Reads an unsigned int value representing flags into a local value
  • If reader.context.version >= Version.lanePosition then reads m_LanePosition (float); otherwise leaves it as default (0)
  • Assigns m_Flags from the read uint value This method is version-aware, ensuring compatibility with saves that predate the addition of m_LanePosition.

Usage Example

// Example: create and attach a HumanCurrentLane component to an entity in a system
using Unity.Entities;
using Unity.Mathematics;
using Colossal.Mathematics;
using Game.Creatures;

// Creating from flags only
var laneComponent = new HumanCurrentLane(CreatureLaneFlags.None);

// Creating from an AccessLane (pseudo-code; actual AccessLane comes from pathfinding/route systems)
AccessLane accessLane = GetAccessLaneSomehow();
var laneFromAccess = new HumanCurrentLane(accessLane, CreatureLaneFlags.SomeFlag);

// Add or set component on an entity
EntityManager entityManager = World.DefaultGameObjectInjectionWorld.EntityManager;
Entity humanEntity = /* an existing human entity */;
if (!entityManager.HasComponent<HumanCurrentLane>(humanEntity))
{
    entityManager.AddComponentData(humanEntity, laneFromAccess);
}
else
{
    entityManager.SetComponentData(humanEntity, laneFromAccess);
}

// Serialization is handled by the game's writer/reader pipeline; this component implements ISerializable
// so it will be saved/restored automatically by the game's serialization system. The Deserialize method
// checks reader.context.version to stay compatible with older save formats (Version.lanePosition).