Game.Creatures.Human
Assembly: Assembly-CSharp
Namespace: Game.Creatures
Type: struct
Base: IComponentData, IQueryTypeParameter, ISerializable
Summary: Represents a data-only ECS component that stores the state flags for a human creature in the game. Implementing Unity.Entities.IComponentData makes this struct usable as an entity component in the DOTS/ECS world. Implementing Colossal.Serialization.Entities.ISerializable provides custom save/load behavior by serializing the flags as a uint. The HumanFlags enum (defined elsewhere) encodes the per-human bitflags (states such as alive, moving, sleeping, etc.).
Fields
public HumanFlags m_Flags
Holds the bitfield describing the human's current state. The underlying value is serialized as a uint. Treat this field as the authoritative state for the component; changes should be done through ECS operations (Add/SetComponentData) so systems can react properly.
Properties
- This type has no properties.
All data is exposed through the public field m_Flags and managed through ECS operations and the Serialize/Deserialize methods.
Constructors
public Human(HumanFlags flags)
Initializes a new Human component and sets the m_Flags field to the provided flags value. Use this when creating or setting the component on an entity.
Methods
-
public void Serialize<TWriter>(TWriter writer) where TWriter : IWriter
Writes the HumanFlags value to the provided writer as a uint. This implements the required ISerializable behavior so the component's state will be saved with the entity. -
public void Deserialize<TReader>(TReader reader) where TReader : IReader
Reads a uint from the provided reader and reconstructs the HumanFlags value. This restores the component state when entities are loaded from saved data.
Usage Example
// Example: creating an entity and adding the Human component
EntityManager entityManager = World.DefaultGameObjectInjectionWorld.EntityManager;
EntityArchetype archetype = entityManager.CreateArchetype(typeof(Game.Creatures.Human));
Entity humanEntity = entityManager.CreateEntity(archetype);
// Assume HumanFlags is an enum with values, e.g. HumanFlags.IsAlive
var humanComponent = new Game.Creatures.Human(HumanFlags.IsAlive);
entityManager.SetComponentData(humanEntity, humanComponent);
// Example: manual serialize/deserialize usage (normally done by the game's save system)
void SaveHuman<TWriter>(in Game.Creatures.Human human, TWriter writer) where TWriter : IWriter
{
human.Serialize(writer);
}
Game.Creatures.Human LoadHuman<TReader>(TReader reader) where TReader : IReader
{
var h = new Game.Creatures.Human();
h.Deserialize(reader);
return h;
}
{{ Additional notes: - This struct is blittable and safe to use in jobs and burst-compiled systems, provided HumanFlags is a simple enum with an underlying integral type. - Because the component uses a single field for state, adding or removing specific states is done by setting or masking m_Flags and then writing the component back to the entity via EntityManager. - The serialization writes the raw underlying uint value. If the enum's underlying size or semantics change, saved data compatibility may be affected; maintain compatibility by preserving the enum layout or adding migration logic in higher-level save handlers. - Located at Game/Creatures/Human.cs in the game/mod project; common assembly name is Assembly-CSharp for Cities: Skylines 2 mods. }}