Skip to content

Game.Common.Terrain

Assembly: Assembly-CSharp
Namespace: Game.Common

Type: struct

Base: System.ValueType
Implements: Unity.Entities.IComponentData, Unity.Entities.IQueryTypeParameter

Summary:
A lightweight marker/tag component used with Unity's DOTS/ECS in Cities: Skylines 2 mod code. The struct is empty by design and annotated with [StructLayout(LayoutKind.Sequential, Size = 1)] so it occupies one byte—this prevents it from being treated as a true zero-sized type and ensures stable behavior when used as an ECS component or as a query type parameter.


Fields

  • This struct declares no instance fields.
    {{ This is an intentionally empty marker component; the StructLayout attribute (Size = 1) ensures it has a non-zero size for ECS and native interop reasons. }}

Properties

  • This struct declares no properties.
    {{ Because Terrain is a simple tag component it exposes no state or properties. }}

Constructors

  • The struct uses the implicit default parameterless constructor.
    {{ There are no custom constructors defined. Create an instance with new Terrain() when needed (though no internal data exists). }}

Methods

  • This struct defines no methods.
    {{ Terrain is intended solely as a tag/IComponentData and IQueryTypeParameter for queries; all behavior is provided by systems that check for the presence of this component on entities. }}

Usage Example

using Unity.Entities;

// Add the Terrain tag to a created entity
EntityManager em = World.DefaultGameObjectInjectionWorld.EntityManager;
Entity e = em.CreateEntity();
em.AddComponentData(e, new Game.Common.Terrain());

// Query for entities that have the Terrain tag inside a SystemBase
public partial class TerrainProcessingSystem : SystemBase
{
    protected override void OnUpdate()
    {
        // Process entities that have the Terrain tag
        Entities
            .WithAll<Game.Common.Terrain>()
            .ForEach((Entity entity) =>
            {
                // Do work for terrain-tagged entities
            }).Schedule();
    }
}

{{ Notes: - Implementing IQueryTypeParameter allows this type to be used in compile-time query patterns like WithAll(). - The attribute [StructLayout(LayoutKind.Sequential, Size = 1)] is commonly used for marker components to avoid zero-sized type corner cases in native interop or job systems. - Because the component carries no data, systems should treat it as a presence/absence flag only. }}