Game.CommuterHousehold
Assembly: Assembly-CSharp (game)
Namespace: Game.Citizens
Type: struct
Base: Implements Unity.Entities.IComponentData, Unity.Entities.IQueryTypeParameter, Colossal.Serialization.Entities.ISerializable
Summary:
CommuterHousehold is an ECS component used by the game to mark a household entity that has commuter behavior. It stores a reference to the original entity the commuters came from (m_OriginalFrom) and implements ISerializable so that this Entity reference can be written to and read from the save data. Deserialize is guarded by a version check (Version.commuterOriginalFrom) so older save formats that lack this field are handled safely.
Fields
public Unity.Entities.Entity m_OriginalFrom
Holds the Entity reference for the original source/location of the commuter household. This value is written during serialization and restored during deserialization (when the save version supports it). Default for an uninitialized struct will be Entity.Null.
Properties
- This type does not expose any properties.
Constructors
public CommuterHousehold()
Implicit parameterless struct constructor is available. Typical initialization is done by assigning m_OriginalFrom directly when creating or adding the component.
Methods
-
public void Serialize<TWriter>(TWriter writer) where TWriter : IWriter
Writes the m_OriginalFrom Entity to the provided writer. Used by the game's save system to persist the reference. -
public void Deserialize<TReader>(TReader reader) where TReader : IReader
Reads m_OriginalFrom from the reader if the save version is at least Version.commuterOriginalFrom. The method uses a version check to avoid reading a field that does not exist in older save formats: - If reader.context.version >= Version.commuterOriginalFrom, reader.Read(out m_OriginalFrom) is invoked.
- Otherwise the field is left at its default value (Entity.Null).
Usage Example
// Create or obtain an entity and set the CommuterHousehold component:
var entityManager = World.DefaultGameObjectInjectionWorld.EntityManager;
Entity householdEntity = entityManager.CreateEntity();
// Suppose originalEntity is the Entity where commuters originated:
Entity originalEntity = /* obtain original entity */ Entity.Null;
// Add and initialize the component
var commuter = new Game.Citizens.CommuterHousehold { m_OriginalFrom = originalEntity };
entityManager.AddComponentData(householdEntity, commuter);
// The game save system will call Serialize/Deserialize automatically.
// If you need to call them manually (for custom writer/reader):
// writer.Write(commuter.m_OriginalFrom);
// reader.Read(out commuter.m_OriginalFrom) // guarded by version check internally
Notes: - The component is a plain data struct and intended to be used with Unity's ECS systems and queries. - The Version.commuterOriginalFrom constant controls whether the originalFrom value exists in a given save version; this ensures backward compatibility when loading older saves.