Skip to content

Game.Creatures.AnimalCurrentLane

Assembly: Game
Namespace: Game.Creatures

Type: struct

Base: IComponentData, IQueryTypeParameter, ISerializable

Summary:
Represents the current lane-related navigation state for a creature (animal). Stores the lane entity the creature is currently on, the next lane it will move to (if any), queue/spacing information, spline/curve positions along the lane, and lane-specific flags. Implements serialization/deserialization with version-aware handling for fields added in later versions (animalNavigation).


Fields

  • public Entity m_Lane
    This is the Entity representing the current lane the creature is occupying or following.

  • public Entity m_NextLane
    Entity reference to the next lane the creature will transition to (Entity.Null when none). Populated and serialized/deserialized when the runtime version supports it.

  • public Entity m_QueueEntity
    Entity used for queueing logic (e.g., spacing/slot entity). Can be Entity.Null when not queued.

  • public Sphere3 m_QueueArea
    A Sphere3 describing the area used for queueing or spacing checks around the queue entity. Type comes from Colossal.Mathematics.

  • public float2 m_CurvePosition
    The position along the lane's curve (spline) for the current lane, stored as a float2 (likely representing parametric coordinates or 2D offset along the lane).

  • public float2 m_NextPosition
    The position along the next lane's curve (float2). Written/read only when next-lane data is present.

  • public CreatureLaneFlags m_Flags
    Flags describing properties/behavior of the current lane for this creature (uses the CreatureLaneFlags enum).

  • public CreatureLaneFlags m_NextFlags
    Flags for the next lane (CreatureLaneFlags). Present/used when next lane information is serialized (version dependent).

  • public float m_LanePosition
    A float representing a scalar lane position (likely distance or normalized position along the lane). Serialized/deserialized.

Properties

  • This type does not declare any properties. It only contains public fields and methods required by the implemented interfaces.

Constructors

  • public AnimalCurrentLane(Entity lane, float curvePosition, CreatureLaneFlags flags)
    Initializes a new AnimalCurrentLane with the given lane Entity, curve position, and flags. Other fields are set to defaults: m_NextLane and m_QueueEntity to Entity.Null, m_QueueArea default-initialized, m_NextPosition zero, m_NextFlags zero, and m_LanePosition zero.

  • public AnimalCurrentLane(CreatureLaneFlags flags)
    Initializes a new AnimalCurrentLane with only flags specified. Lane and other Entity fields default to Entity.Null, positions to zero, and m_NextFlags zero.

Methods

  • public void Serialize<TWriter>(TWriter writer) where TWriter : IWriter
    Writes the component state to the provided writer in the following order:
  • m_Lane (Entity)
  • m_CurvePosition (float2)
  • m_Flags (written as uint)
  • m_LanePosition (float)
  • m_NextLane (Entity)
  • m_NextPosition (float2)
  • m_NextFlags (written as uint)

Note: The implementation writes next-lane related fields unconditionally; the Deserialize method however checks reader version when reading them.

  • public void Deserialize<TReader>(TReader reader) where TReader : IReader
    Reads state from the provided reader. Reads in the order matching Serialize for backwards compatibility. After reading m_Lane, m_CurvePosition, an unsigned integer for flags, and m_LanePosition, it assigns m_Flags from the read value. It conditionally reads next-lane fields (m_NextLane, m_NextPosition, and m_NextFlags) only when reader.context.version >= Version.animalNavigation. This ensures compatibility with saves prior to the animalNavigation version.

Version compatibility note: code relies on a Version enum/constant (Version.animalNavigation) to determine whether next-lane fields exist in the serialized stream.

Usage Example

// Example: Creating and assigning an AnimalCurrentLane component to an entity
var laneEntity = /* obtain lane Entity */;
var flags = CreatureLaneFlags.None; // example enum value
var curvePos = new float2(0.5f, 0f);

var currentLane = new AnimalCurrentLane(laneEntity, curvePos.x, flags);

// Using Unity.Entities (EntityManager) to add the component to an entity:
EntityManager entityManager = World.DefaultGameObjectInjectionWorld.EntityManager;
Entity animalEntity = entityManager.CreateEntity();
entityManager.AddComponentData(animalEntity, currentLane);

// When reading serialized data, Deserialize will only populate next-lane fields
// if the saved data's version >= Version.animalNavigation.

{{ Additional notes: - Types referenced: - Entity: Unity.Entities.Entity - float2: Unity.Mathematics.float2 - Sphere3: Colossal.Mathematics.Sphere3 - CreatureLaneFlags: enum used to encode lane-specific behavior for creatures. - Serialization order must be preserved across Serialize/Deserialize to maintain compatibility. - The struct implements IQueryTypeParameter so it can be used in ECS query contexts/service APIs expecting that marker. - When modifying or extending this struct, be careful to maintain version-aware changes and update serialization version checks accordingly. }}