Game.Companies.StorageCompany
Assembly: Game (Game.dll)
Namespace: Game.Companies
Type: struct
Base: IComponentData, IQueryTypeParameter, ISerializable
Summary:
StorageCompany is a lightweight ECS component used to store the last trade partner for a company entity in Cities: Skylines 2. It holds a Unity.Entities.Entity reference that points to the last entity the company traded with. The component implements Colossal's ISerializable so its data can be persisted by the game's save/load serialization system.
Fields
public Entity m_LastTradePartner
Stores the Entity reference of the company's last trade partner. This will be Entity.Null when there is no recorded partner. Because this is a public field on a struct, read/write operations modify a copy unless used via the ECS API (e.g., EntityManager.Get/SetComponentData or within an IComponentData job).
Properties
- This type has no properties.
All data is exposed via the public field(s) above.
Constructors
public StorageCompany()
No custom constructor is defined in source; the default parameterless struct constructor is used. Initialize instances by setting m_LastTradePartner explicitly or via ECS SetComponentData.
Methods
-
public void Serialize<TWriter>(TWriter writer) where TWriter : IWriter
Writes the m_LastTradePartner Entity reference to the provided writer. Used by the game's serialization system to persist component state. -
public void Deserialize<TReader>(TReader reader) where TReader : IReader
Reads an Entity reference from the provided reader into m_LastTradePartner. Used when loading saved game state.
Notes: - The (de)serialization methods rely on Colossal.Serialization.Entities writer/reader implementations that know how to encode/decode Unity.Entities.Entity references. - Because the component is a struct and implements ISerializable, ensure deserialized instances are written back to the entity via EntityManager.SetComponentData to persist the restored value in the ECS world.
Usage Example
// Add or update a StorageCompany component on an entity
var companyEntity = entityManager.CreateEntity(typeof(StorageCompany));
var storage = new StorageCompany { m_LastTradePartner = lastPartnerEntity };
entityManager.SetComponentData(companyEntity, storage);
// Read the component
var current = entityManager.GetComponentData<StorageCompany>(companyEntity);
var lastPartner = current.m_LastTradePartner;
// Example of manual serialization/deserialization using readers/writers
// (In practice the game's save system will call these)
var storageToSave = entityManager.GetComponentData<StorageCompany>(companyEntity);
storageToSave.Serialize(writer); // writer is an IWriter implementation
var loadedStorage = new StorageCompany();
loadedStorage.Deserialize(reader); // reader is an IReader implementation
entityManager.SetComponentData(companyEntity, loadedStorage);
Additional information: - Typical usage is within company-related systems that manage trading and partner relationships. - Because this component only stores a single Entity reference, it's cheap to add to many entities. - Be mindful when accessing Entity fields from jobs — use appropriate ECS patterns (IJobChunk/IJobForEach, component lookups, or pass the component via the job struct) to avoid accidental copies or race conditions.