Skip to content

Game.Objects.Surface

Assembly:
Assembly-CSharp

Namespace:
Game.Objects

Type:
struct

Base:
Implements: IComponentData, IQueryTypeParameter, ISerializable

Summary:
Represents per-surface (tile/segment) environmental state used by the game's simulation and serialization systems. Holds compact (byte) values for current and accumulated wetness and snow, plus a dirtiness value. Designed to be used as a Unity ECS component (IComponentData) and supports save/load via Colossal's serialization interfaces (ISerializable). Fields are stored and serialized in a fixed order — important when reading/writing saved data.


Fields

  • public byte m_Wetness
    Current wetness level of the surface. Range 0–255 (byte). Used to drive wet visuals and any wetness-related gameplay effects.

  • public byte m_SnowAmount
    Current snow cover amount on the surface. Range 0–255. Affects visuals and snow-related simulation.

  • public byte m_AccumulatedWetness
    Accumulated wetness value (e.g., integrated over time for smoothing or thresholds). Range 0–255.

  • public byte m_AccumulatedSnow
    Accumulated snow value (e.g., for gradual snow buildup or melting). Range 0–255.

  • public byte m_Dirtyness
    Amount of dirt/grime on the surface. Range 0–255. May be used for visual tinting or maintenance logic.

Properties

  • This struct defines no properties. Interaction is via the public fields and the provided serialization methods.

Constructors

  • public Surface()
    Implicit default value-type constructor. All byte fields default to 0. You can also initialize with an object initializer:
var s = new Surface {
    m_Wetness = 10,
    m_SnowAmount = 0,
    m_AccumulatedWetness = 5,
    m_AccumulatedSnow = 0,
    m_Dirtyness = 2
};

Methods

  • public void Serialize<TWriter>(TWriter writer) where TWriter : IWriter
    Writes the surface fields to the provided writer in the following order: m_Wetness, m_SnowAmount, m_AccumulatedWetness, m_AccumulatedSnow, m_Dirtyness. The ordering must be preserved when deserializing.

  • public void Deserialize<TReader>(TReader reader) where TReader : IReader
    Reads the surface fields from the provided reader into this struct using the same order as Serialize. Uses ref locals to write directly into the struct fields.

Notes: - These methods integrate with Colossal.Serialization.Entities and are intended for the game's save/load pipeline. - Keep field order and types unchanged unless you also handle versioning in serialization to maintain save compatibility.

Usage Example

// Create and initialize a Surface component
var surface = new Surface {
    m_Wetness = 128,
    m_SnowAmount = 0,
    m_AccumulatedWetness = 128,
    m_AccumulatedSnow = 0,
    m_Dirtyness = 10
};

// Example: add to an entity (Unity.Entities context)
EntityManager em = World.DefaultGameObjectInjectionWorld.EntityManager;
Entity e = em.CreateEntity();
em.AddComponentData(e, surface);

// Example: custom serialization (pseudo-code, depends on IWriter implementation)
using (var writer = new SomeWriter(stream)) {
    surface.Serialize(writer);
}

// Example: deserialization
Surface loaded = new Surface();
using (var reader = new SomeReader(stream)) {
    loaded.Deserialize(reader);
}

{{ Additional notes: - As an IComponentData struct, Surface is intended to be small and blittable — using byte fields keeps memory usage low when stored across many entities. - If you change the field layout, update serialization logic and migration/versioning to avoid corrupting saved games. - Use accumulated fields to implement time-averaged effects (smoothing) rather than writing simulation logic directly to the instantaneous fields where appropriate. }}