Skip to content

Game.Buildings.EmergencyGenerator

Assembly:
Assembly-CSharp (game assembly) — may also appear in your mod assembly depending on where the code is compiled.
{{ This struct is defined in the game's codebase (commonly in Assembly-CSharp). If you recompile it into a mod, the actual assembly name will be your mod's assembly. }}

Namespace:
Game.Buildings

Type:
struct

Base:
IComponentData, IQueryTypeParameter, ISerializable

Summary:
EmergencyGenerator is a lightweight ECS component (Unity.Entities) representing the production value of an emergency generator building. It stores an integer production value and implements Colossal.Serialization.Entities.ISerializable to persist that value when saving/loading. Because it implements IComponentData and IQueryTypeParameter it is intended to be attached to entities and used in ECS queries and systems.
{{ Typical usage: attach the component to building entities to track the generator's current production (units are game-specific). The component is trivially serializable via the provided generic Serialize/Deserialize methods. }}


Fields

  • public int m_Production
    {{ The integer production value for this emergency generator. Default is 0 for the implicit parameterless constructor. This field is written and read by the Serialize/Deserialize methods so it will be saved and loaded with the entity. The semantic unit (e.g., energy units, power units) depends on the surrounding game systems that consume this value. }}

Properties

{{ This type defines no properties. It only exposes the public field m_Production. }}

Constructors

  • public EmergencyGenerator()
    {{ As a struct, EmergencyGenerator has an implicit public parameterless constructor that initializes m_Production to 0. You can also initialize the field inline when creating an instance. }}

Methods

  • public void Serialize<TWriter>(TWriter writer) where TWriter : IWriter
    {{ Writes the component state to a writer for persistence. The implementation simply calls writer.Write(m_Production). This is used by the game's serialization pipeline to save the component value. }}

  • public void Deserialize<TReader>(TReader reader) where TReader : IReader
    {{ Restores the component state from a reader during load. The implementation reads m_Production via reader.Read(out m_Production). Ensure that the reader/writer pair used during save/load is compatible with this format. }}

Usage Example

// Create an entity with the EmergencyGenerator component and set production.
var entityManager = World.DefaultGameObjectInjectionWorld.EntityManager;
var archetype = entityManager.CreateArchetype(typeof(Game.Buildings.EmergencyGenerator));
Entity genEntity = entityManager.CreateEntity(archetype);

// Set production to 150 (example value)
entityManager.SetComponentData(genEntity, new Game.Buildings.EmergencyGenerator { m_Production = 150 });

// Example: reading the value in a system
public partial class GeneratorSystem : SystemBase
{
    protected override void OnUpdate()
    {
        Entities.ForEach((ref Game.Buildings.EmergencyGenerator gen) =>
        {
            int currentProduction = gen.m_Production;
            // ... use currentProduction ...
        }).Schedule();
    }
}

// Serialization is handled by the component's methods automatically by the game's serializer.
// Manually calling (conceptual example) - real writer/reader instances are provided by the engine:
void SaveComponent<TWriter>(ref Game.Buildings.EmergencyGenerator gen, TWriter writer) where TWriter : IWriter
{
    gen.Serialize(writer);
}

{{ Notes: Keep in mind that m_Production is a plain int field — any invariants (e.g., non-negative, capped value) must be enforced by the systems that modify this component. Since this is an IComponentData struct, avoid holding references or managed resources in it. }}