Skip to content

Game.CurrentTransport

Assembly: Game (main game assembly)
Namespace: Game.Citizens

Type: struct

Base: Implements Unity.Entities.IComponentData, Unity.Entities.IQueryTypeParameter, Colossal.Serialization.Entities.ISerializable

Summary:
Represents a citizen's current transport as an ECS component. Stores a Unity.Entities.Entity reference to the transport (vehicle, tram, bus, etc.). Implements serialization so the entity reference can be written/read by the game's serialization system (Colossal.Serialization). Useful for systems that need to track or persist which transport a citizen is currently using.


Fields

  • public Unity.Entities.Entity m_CurrentTransport
    Holds the Entity reference to the transport currently associated with this citizen. When not set, the field will be the default Entity value (typically Entity.Null). This field is the value serialized/deserialized by the ISerializable implementation.

Properties

  • This struct exposes no properties.

Constructors

  • public CurrentTransport(Unity.Entities.Entity transport)
    Initializes a new CurrentTransport with the provided transport entity. Use this to set the initial transport reference when creating or updating the component. Note that, as a struct, a parameterless default constructor also exists (which initializes m_CurrentTransport to the default Entity value).

Methods

  • public void Serialize<TWriter>(TWriter writer) where TWriter : IWriter
    Writes the m_CurrentTransport Entity to the provided writer. Used by the Colossal.Serialization system when saving/persisting component data.

  • public void Deserialize<TReader>(TReader reader) where TReader : IReader
    Reads an Entity from the provided reader into m_CurrentTransport. Used by the Colossal.Serialization system when loading/restoring component data.

Usage Example

// Example: assign a transport entity to a citizen entity
Entity transportEntity = /* obtain transport entity from your systems */;
Entity citizenEntity = /* obtain citizen entity */;

var currentTransport = new Game.Citizens.CurrentTransport(transportEntity);
entityManager.AddComponentData(citizenEntity, currentTransport);

// During save/load, the game's serialization system will call Serialize/Deserialize