Skip to content

Game.Objects.UtilityObject

Assembly: Game (inferred; compiled into the game's assemblies such as Assembly-CSharp)
Namespace: Game.Objects

Type: struct

Base: IComponentData, IQueryTypeParameter, IEmptySerializable

Summary:
UtilityObject is an empty/tag ECS component used to mark entities as utility objects. It carries no data; the presence of the component is used as a marker for systems and queries. The struct is annotated with StructLayout(LayoutKind.Sequential, Size = 1) to ensure a non-zero size for interop/serialization purposes and to satisfy the game's/custom serializer expectations.


Fields

  • This struct declares no instance fields. It is intentionally empty and used purely as a marker/tag component.

Properties

  • This struct exposes no properties. Its type itself is the marker.

Constructors

  • public UtilityObject() (implicit default)
    The type relies on the implicit parameterless constructor; you create instances with default(UtilityObject) or new UtilityObject().

Methods

  • This struct declares no methods. Behavior is provided by systems that check for the presence of the component.

Notes and Implementation Details

  • Interfaces implemented:
  • IComponentData — makes the type a Unity ECS component.
  • IQueryTypeParameter — allows the type to be used as a query parameter in ECS queries (marker-style usage).
  • IEmptySerializable — indicates special handling by the game's serialization system for empty components.
  • The attribute [StructLayout(LayoutKind.Sequential, Size = 1)] forces the struct to occupy a byte, avoiding issues with zero-sized types when bridging to native code or custom serializers used by the game.
  • Typical use is to add or remove the component to/from entities to indicate they are utility objects; systems then filter entities by the presence of this component.

Usage Example

// Create an entity that carries the UtilityObject tag
var em = World.DefaultGameObjectInjectionWorld.EntityManager;
Entity e = em.CreateEntity(typeof(UtilityObject)); // creates entity with the tag

// Or add the tag to an existing entity
em.AddComponentData(e, new UtilityObject()); // empty struct instance as marker

// Querying for entities with the tag (example)
var query = em.CreateEntityQuery(typeof(UtilityObject));
using (var entities = query.ToEntityArray(Unity.Collections.Allocator.TempJob))
{
    // process utility object entities
}