Skip to content

Game.ServiceObjectData

Assembly: Assembly-CSharp.dll
Namespace: Game.Prefabs

Type: struct

Base: IComponentData, IQueryTypeParameter, ISerializable

Summary:
ServiceObjectData is a small ECS component that stores a reference to a "service" Entity (for example a service building/object instance) used by prefab-related systems. It implements Colossal.Serialization's ISerializable so it can be written/read by the game's serialization pipeline, and IQueryTypeParameter to be used in ECS query patterns.


Fields

  • public Unity.Entities.Entity m_Service
    Holds the Entity reference to the service object associated with this component. This is the primary data carried by the component and is serialized/deserialized by the ISerializable implementation.

Properties

  • (none)
    This struct does not define any properties.

Constructors

  • (implicit) public ServiceObjectData()
    Default (implicit) struct constructor. Initialize m_Service explicitly when creating the struct.

Methods

  • public void Serialize<TWriter>(TWriter writer) where TWriter : IWriter
    Writes the m_Service Entity to the provided writer. Used by the Colossal.Serialization system to persist this component's data.

  • public void Deserialize<TReader>(TReader reader) where TReader : IReader
    Reads the m_Service Entity from the provided reader into this component. Used by the Colossal.Serialization system when loading or synchronizing state.

Remarks / Notes

  • As an IComponentData, ServiceObjectData is intended to be attached to Entities in the Unity ECS (DOTS) world. Access and modification should follow ECS patterns (via EntityManager / Systems) to remain thread-safe and deterministic.
  • The Entity value stored in m_Service is a plain Unity.Entities.Entity struct (an ID/handle); systems that consume this component should validate that the referenced Entity exists and has the expected components before operating on it.
  • The serialization methods use generic IWriter/IReader constraints from Colossal.Serialization.Entities. The actual writer/reader implementation is provided by the game engine's serialization infrastructure.

Usage Example

// Add the component to an entity (ECS way)
var entityManager = World.DefaultGameObjectInjectionWorld.EntityManager;
var myEntity = entityManager.CreateEntity();
Unity.Entities.Entity serviceEntity = /* obtain a service entity from prefab/spawner */;
entityManager.AddComponentData(myEntity, new Game.Prefabs.ServiceObjectData { m_Service = serviceEntity });

// Example of explicit serialization (conceptual)
// TWriter and TReader are provided by the game's serialization system; this shows intent.
var data = new Game.Prefabs.ServiceObjectData { m_Service = serviceEntity };
// writer.Write / reader.Read are invoked by the engine; calling Serialize/Deserialize directly is possible
// if you have a suitable writer/reader instance:
data.Serialize(myWriter);
// ...
data.Deserialize(myReader);