Skip to content

Game.Objects.Elevation

Assembly:
Namespace: Game.Objects

Type: struct

Base: IComponentData, IQueryTypeParameter, ISerializable

Summary: Represents the elevation state for a game object. Holds a single floating-point elevation value and a set of flags describing additional elevation-related state. Implements serialization so instances can be written to and read from Colossal's binary format. The deserialization handles version compatibility by only reading the flags field if the saved data version supports stacked objects.


Fields

  • public System.Single m_Elevation Stores the elevation value in world units (single-precision float). Serialized first when writing this struct.

  • public ElevationFlags m_Flags Bitfield/enum that encodes additional elevation-related flags. Serialized as a single byte during Write; when reading, the flags are only read if the saved data version is at least Version.stackedObjects — otherwise they remain at their default value.

Properties

  • None This struct exposes its data as public fields and does not define C# properties.

Constructors

  • public Elevation(float elevation, ElevationFlags flags) Creates a new Elevation instance with the supplied elevation value and flags.

Methods

  • public void Serialize<TWriter>(TWriter writer) where TWriter : IWriter Writes the struct to the provided writer. Behavior:
  • Writes m_Elevation as a float.
  • Writes m_Flags cast to a single byte.

  • public void Deserialize<TReader>(TReader reader) where TReader : IReader Reads the struct from the provided reader. Behavior:

  • Reads m_Elevation from the reader.
  • If reader.context.version >= Version.stackedObjects then reads a single byte and assigns it to m_Flags.
  • If the saved data is from an older version (before stackedObjects) the flags are not present and remain at the default value.

Notes: - The struct implements IComponentData so it can be used as ECS component data. - The IQueryTypeParameter implementation is a marker used by the ECS query machinery (no explicit code shown in this file). - Version compatibility is handled during deserialization to avoid breaking older save formats.

Usage Example

// Constructing an Elevation value
var elev = new Elevation(12.5f, ElevationFlags.None);

// Serializing (pseudo-code — TWriter is provided by Colossal's serialization system)
elev.Serialize(writer);

// Deserializing (pseudo-code)
Elevation read = default;
read.Deserialize(reader);

// Using as ECS component (example)
EntityManager em = World.DefaultGameObjectInjectionWorld.EntityManager;
Entity e = em.CreateEntity();
em.AddComponentData(e, new Elevation(5.0f, ElevationFlags.SomeFlag));

{{ Additional info: - ElevationFlags is expected to be an enum (byte-sized in serialization) defined elsewhere in the codebase; check its definition for available flag values and semantics. - The Version.stackedObjects check ensures backward compatibility with save files created before the stacked-objects feature existed. If you add new fields later, follow the same pattern: write them in Serialize and guard reads by version checks in Deserialize. - Because m_Flags is serialized as a byte, avoid adding values to ElevationFlags outside of the 0-255 range if you expect them to be persisted. }}