Skip to content

Game.Events.Event

Assembly: Game
Namespace: Game.Events

Type: struct

Base: IComponentData, IQueryTypeParameter, IEmptySerializable

Summary:
A lightweight, empty marker component used by the ECS (Unity.Entities) to represent an event/token. The struct is deliberately empty and decorated with StructLayout(LayoutKind.Sequential, Size = 1) so it has a defined (non-zero) size for serialization and engine interop. Implements IComponentData so it can be added to entities, IQueryTypeParameter so it can be used with query APIs, and IEmptySerializable to cooperate with Colossal's serialization system.


Fields

  • This struct declares no instance fields.
    The StructLayout attribute enforces a size of 1 byte but there are no user-visible fields.

Properties

  • This struct exposes no properties.

Constructors

  • public Event() (implicit default)
    As a value type, Event has the implicit parameterless constructor. No initialization is required because it carries no data.

Methods

  • This struct defines no methods. It is intended to be used purely as a marker component/tag.

Notes for modders / additional info

  • StructLayout(LayoutKind.Sequential, Size = 1): Ensures the struct occupies a single byte in memory. This is commonly used for empty marker components to avoid zero-sized types that can cause issues with serialization or native interop.
  • IEmptySerializable: Indicates to Colossal.Serialization that the type is empty and should be handled accordingly during save/load operations.
  • IQueryTypeParameter: Allows the type to be used as a parameter in entity query construction APIs (e.g., as a generic type argument in some query helpers).
  • Typical usage pattern: use this as a tag to signal that an entity represents an event or that some processing must occur once. Systems can add this component to entities when enqueuing an event and remove it after processing.

Usage Example

// Create an entity and tag it with the Event marker
var entityManager = World.DefaultGameObjectInjectionWorld.EntityManager;
var e = entityManager.CreateEntity();
entityManager.AddComponent<Game.Events.Event>(e);

// In a SystemBase, find and process entities that have the Event marker
public partial class ExampleEventSystem : SystemBase
{
    protected override void OnUpdate()
    {
        var em = EntityManager;
        Entities
            .WithAll<Game.Events.Event>()
            .ForEach((Entity entity) =>
            {
                // Handle the event associated with 'entity' here...

                // Remove the marker once processed
                em.RemoveComponent<Game.Events.Event>(entity);
            }).WithoutBurst().Run();
    }
}