Game.Simulation.Dispatched
Assembly: Game (inferred from file path)
Namespace: Game.Simulation
Type: public struct Dispatched
Base: Implements IComponentData, IQueryTypeParameter, ISerializable
Summary:
Component (value type) used in the game's ECS to mark or carry a "handler" Entity for dispatched operations. It stores a single Entity reference (m_Handler) and implements custom binary serialization/deserialization via the Colossal.Serialization.Entities ISerializable pattern. The Deserialize method contains a compatibility branch for saved/serialized data from versions older than Version.dispatchRefactoring (it reads and discards an extra uint in that case).
Fields
public Unity.Entities.Entity m_Handler
Holds the Entity that acts as the handler for this dispatched item. This field is serialized/deserialized by the ISerializable implementation.
Properties
- This type defines no properties.
Constructors
public Dispatched(Entity handler)
Creates a new Dispatched component with the provided handler Entity. Example usage: new Dispatched(handlerEntity).
Methods
-
public void Serialize<TWriter>(TWriter writer) where TWriter : IWriter
Writes the m_Handler Entity to the writer. This method implements the ISerializable contract for saving the component state. -
public void Deserialize<TReader>(TReader reader) where TReader : IReader
Reads the handler Entity back from the reader into m_Handler. For backward compatibility, if reader.context.version < Version.dispatchRefactoring, the method reads an additional uint (and ignores it) to maintain compatibility with older serialized layouts.
Notes: - The generic constraints require TWriter : IWriter and TReader : IReader from Colossal.Serialization.Entities. - Deserialize uses a ref local to assign the read value directly into the field.
Usage Example
// Creating the component and setting the handler entity
var dispatched = new Dispatched(handlerEntity);
// Typical ECS usage — adding the component to an entity (pseudo-code)
entityManager.AddComponentData(someEntity, dispatched);
// Serialization example (called by the game's save system)
dispatched.Serialize(writer);
// Deserialization example (called by the game's load system)
Dispatched loaded = default;
loaded.Deserialize(reader);
entityManager.SetComponentData(someEntity, loaded);
Additional notes: - This component is a lightweight data carrier suitable for queries and job systems (it implements IQueryTypeParameter). - Be aware of the version check in Deserialize: Version.dispatchRefactoring is used to decide whether to read an extra legacy uint; ensure compatibility when modifying serialization format.