Skip to content

Game.Buildings.TrafficSpawner

Assembly:
Namespace: Game.Buildings

Type: struct

Base: IComponentData, IQueryTypeParameter, ISerializable

Summary: Represents an ECS component that holds an Entity reference to a traffic request associated with a building. This struct is used in the game's DOTS/ECS systems to attach pending traffic-spawn information to an entity (typically a building or request entity). It implements ISerializable so the contained Entity reference can be written to and restored from save/serialization streams, and IQueryTypeParameter so it can be used directly in entity queries or archetypes.


Fields

  • public Unity.Entities.Entity m_TrafficRequest Holds the Entity handle that represents a traffic request (for example, an entity representing a vehicle spawn request or a request record). This value is stored directly in the component and will be written/read by the Serialize/Deserialize methods. Treat this as an entity reference that may need remapping on load.

Properties

  • None. This struct exposes no properties; it is plain component data with a public field.

Constructors

  • public TrafficSpawner() No explicit constructor is defined in source; the default parameterless constructor is provided by the C# compiler for the value type. Initialize the m_TrafficRequest field when adding this component to an entity.

Methods

  • public void Serialize<TWriter>(TWriter writer) where TWriter : IWriter Writes the m_TrafficRequest Entity to the provided writer. Used by the game's serialization system to persist the entity reference. Implementers of IWriter are expected to handle entity reference mapping.

  • public void Deserialize<TReader>(TReader reader) where TReader : IReader Reads an Entity from the provided reader into m_TrafficRequest. Used during load/restore so the component's entity reference is reconstituted. Implementers of IReader are expected to provide the correct mapping from serialized identifiers to runtime Entity values.

Usage Example

// Example: attaching a traffic request entity to a building entity
var spawner = new Game.Buildings.TrafficSpawner
{
    m_TrafficRequest = trafficRequestEntity // an Entity created earlier representing the traffic request
};

// Using EntityManager
entityManager.AddComponentData(buildingEntity, spawner);

// Serialization example (pseudo-code; depends on available writer/reader implementations)
spawner.Serialize(writer);

// Later, when loading:
var loadedSpawner = new Game.Buildings.TrafficSpawner();
loadedSpawner.Deserialize(reader);
entityManager.SetComponentData(buildingEntity, loadedSpawner);

Notes: - Because this component stores an Entity, ensure the serialization system remaps entity references appropriately on load. - Use EntityCommandBuffer when adding/removing this component from entities inside jobs to avoid structural changes in the main thread.