Skip to content

Game.Companies.CompanyData

Assembly:
Namespace: Game.Companies

Type: struct

Base: IComponentData, IQueryTypeParameter, ISerializable

Summary: A lightweight ECS component that stores per-company random seed information and a reference to the company's brand entity. Implements Colossal's ISerializable so the component's state (the Random internal state and the brand Entity) can be written to and read from a save/serialization stream.


Fields

  • public Unity.Mathematics.Random m_RandomSeed Stores the Unity.Mathematics.Random instance used for deterministic random operations for this company. The struct's internal uint state is what is serialized/deserialized (see methods).

  • public Unity.Entities.Entity m_Brand Entity handle referencing the brand associated with the company. This is serialized/deserialized as an Entity, so the serializer will map/resolve the entity handle appropriately when reading/writing game data.

Properties

  • This type does not declare any properties.

Constructors

  • public CompanyData() (default struct constructor) No explicit constructors are defined in the source. Initialize m_RandomSeed and m_Brand manually before use (e.g., new Random(seed) or Random.CreateFromIndex/seed API depending on your Unity.Mathematics version, and set m_Brand to an Entity).

Methods

  • public void Serialize<TWriter>(TWriter writer) where TWriter : IWriter Writes the component data to a writer. Implementation details:
  • Extracts the internal uint state from m_RandomSeed.state and writes it with writer.Write(uint).
  • Writes the m_Brand Entity with writer.Write(Entity). Note: The serializer only persists the Random.state (uint) — not the full Random struct layout — which keeps the serialized form small and deterministic.

  • public void Deserialize<TReader>(TReader reader) where TReader : IReader Reads the component data from a reader. Implementation details:

  • Reads a uint into the m_RandomSeed.state reference via reader.Read(out state), restoring the Random state.
  • Reads the brand Entity via reader.Read(out brand) into m_Brand. The implementation uses ref locals to assign directly into the struct fields.

Usage Example

using Unity.Entities;
using Unity.Mathematics;
using Unity.Collections;
using Game.Companies;

// Create and initialize a CompanyData instance, then add it to an entity
EntityManager em = World.DefaultGameObjectInjectionWorld.EntityManager;
EntityArchetype archetype = em.CreateArchetype(typeof(CompanyData));
Entity companyEntity = em.CreateEntity(archetype);

CompanyData data = new CompanyData();
data.m_RandomSeed = new Random((uint)12345); // initialize deterministic seed
data.m_Brand = Entity.Null; // assign a brand entity if available

em.SetComponentData(companyEntity, data);

// During save/load, the engine's serializer will call Serialize/Deserialize automatically
// because the component implements ISerializable.

Notes and tips: - Ensure you initialize m_RandomSeed with a deterministic seed if reproducible behavior is required. - Because serialization only persists the Random.state (uint) and the Entity handle, any change to how Random is represented internally or to entity mapping/versioning may require updates to these methods. - The component is blittable and lightweight; it is suitable for storing per-company runtime state in ECS.