Skip to content

Game.Events.WaterLevelChange

Assembly: Assembly-CSharp (game/game mod assembly that contains runtime types)
Namespace: Game.Events

Type: struct

Base: System.ValueType
Implements: Unity.Entities.IComponentData, Unity.Entities.IQueryTypeParameter, Colossal.Serialization.Entities.ISerializable

Summary:
Represents a water-level change event (for example tsunami / flood events) stored as an ECS component. Carries intensity values, a danger height threshold, and a direction vector. The struct implements ISerializable so it can be written to / read from the game's save/stream format. Note: Deserialize has a version check when reading direction data — see method notes below for compatibility details.


Fields

  • public float m_Intensity
    Holds the current intensity of the water-level change. Typical usage: how strong the event is at the current moment (unitless). Default 0.0f for a default-initialized struct.

  • public float m_MaxIntensity
    Maximum intensity reached or allowed for this event. Useful for clamping or tracking peak strength.

  • public float m_DangerHeight
    World-space height threshold above which the water level is considered dangerous (used to trigger damage/alerts).

  • public float2 m_Direction
    A 2D vector describing the horizontal direction of the water motion (e.g., tsunami direction). Uses Unity.Mathematics.float2.

Properties

  • None declared on the struct itself. (Behavior is driven by public fields and the implemented interfaces.)

Constructors

  • public WaterLevelChange()
    Default parameterless struct constructor (implicit). All fields default to zero: m_Intensity = 0, m_MaxIntensity = 0, m_DangerHeight = 0, m_Direction = float2(0,0).

Methods

  • public void Deserialize<TReader>(TReader reader) where TReader : IReader
    Reads data from the provided reader in the following order:
  • m_Intensity
  • m_MaxIntensity
  • m_DangerHeight
  • If reader.context.version >= Version.tsunamiDirection then reader.Read(out float2 _) is called (reads a float2 but the value is discarded rather than assigned to m_Direction)

Notes: - The method reads primitive values in the same sequence that Serialize writes them, with one important caveat: when reading the direction field the value is read into a discard variable (float2 _) instead of setting m_Direction. This means that after deserialization m_Direction will remain its default value unless other code sets it. This behavior may be intentional for backward-compatibility reasons or may be a bug — be aware when relying on m_Direction after Deserialize. - The conditional read depends on the serialized data version: older save formats (version < Version.tsunamiDirection) will not contain direction data and the code avoids reading it.

  • public void Serialize<TWriter>(TWriter writer) where TWriter : IWriter
    Writes data to the provided writer in the following order:
  • m_Intensity
  • m_MaxIntensity
  • m_DangerHeight
  • m_Direction (always written)

Notes: - Serialize writes m_Direction unconditionally. Combined with Deserialize's conditional/discarding read, this can lead to inconsistent behavior across versions (the writer always appends the direction data, but older readers may not expect it, and newer readers currently discard it). Keep this in mind when implementing custom readers/writers or when backporting data.

Usage Example

using Unity.Mathematics;
using Unity.Entities;
using Colossal.Serialization.Entities;

// Creating and adding the component to an entity (in a system or setup code)
var change = new Game.Events.WaterLevelChange {
    m_Intensity = 0.75f,
    m_MaxIntensity = 1.0f,
    m_DangerHeight = 5.0f,
    m_Direction = new float2(1.0f, 0.0f) // eastward
};

EntityManager em = World.DefaultGameObjectInjectionWorld.EntityManager;
Entity e = em.CreateEntity();
em.AddComponentData(e, change);

// Serializing the component to a writer (pseudo-code; depends on writer implementation)
TWriter writer = /* obtain writer */;
change.Serialize(writer);

// Deserializing from a reader (pseudo-code; depends on reader implementation)
TReader reader = /* obtain reader */;
var loadedChange = new Game.Events.WaterLevelChange();
loadedChange.Deserialize(reader);
// Note: due to current Deserialize implementation, loadedChange.m_Direction may remain default (0,0)

Additional notes for modders: - Because this struct is an ECS component (IComponentData), it is intended to be attached to entities and queried via EntityQuery / SystemBase. - Be careful when interoperating with the game's serialization system: check reader.context.version handling if you implement custom readers/writers or if you modify the struct layout.