Skip to content

Game.Prefabs.UniqueObject

Assembly: Game
Namespace: Game.Prefabs

Type: class

Base: ComponentBase

Summary:
Marks a prefab as a "unique" placeable object. This prefab component ensures the prefab has the required components for unique objects (PlaceableObjectData and UniqueObjectData), adds the runtime ECS component Game.Objects.UniqueObject to the entity archetype, and sets the PlacementFlags.Unique bit on the PlaceableObjectData when the entity is initialized. This indicates to game systems that only a single instance of this object should be allowed (or that it should be treated as unique by placement logic).


Fields

  • This class declares no instance fields.
    The class is lightweight and only modifies prefab and archetype component sets and runtime component data via methods. It is decorated with a ComponentMenu attribute:
  • [ComponentMenu("Objects/", new Type[] { typeof(StaticObjectPrefab), typeof(MarkerObjectPrefab) })] — places this component under the "Objects/" menu in the prefab/component UI and associates it with the listed prefab types.

Properties

  • This class declares no properties.

Constructors

  • public UniqueObject()
    Default public constructor (implicit). The class relies on its override methods to alter prefab and entity data; no custom construction logic is required.

Methods

  • public override void GetPrefabComponents(HashSet<ComponentType> components)
    Adds required component types to the prefab component list:
  • PlaceableObjectData (read/write)
  • UniqueObjectData (read/write)
    Ensures the prefab will include the data the game expects for unique placeable objects.

  • public override void GetArchetypeComponents(HashSet<ComponentType> components)
    Adds runtime ECS component types to the entity archetype:

  • Game.Objects.UniqueObject (read/write)
    This makes sure entities spawned from the prefab include the runtime component that systems use to identify unique objects.

  • public override void Initialize(EntityManager entityManager, Entity entity)
    Called when the prefab entity is initialized. Behavior:

  • Calls base.Initialize(entityManager, entity).
  • Retrieves the PlaceableObjectData component from the entity, sets the PlacementFlags.Unique bit on its m_Flags field, and writes the updated component back to the entity via entityManager.SetComponentData.
  • Notes: This method assumes the entity has PlaceableObjectData — GetPrefabComponents registers it on the prefab so it should be present. If PlaceableObjectData is missing at runtime, GetComponentData will throw.

Usage Example

// The UniqueObject prefab component is applied to a prefab class (via the editor or prefab code).
// At runtime, Initialize will set the Unique placement flag. To check for uniqueness in a system:

void ProcessEntity(EntityManager entityManager, Entity entity)
{
    var placeable = entityManager.GetComponentData<PlaceableObjectData>(entity);
    bool isUnique = (placeable.m_Flags & PlacementFlags.Unique) != 0;
    if (isUnique)
    {
        // Special handling for unique objects
    }
}

Additional notes: - The class ties together prefab-time component registration and runtime ECS component setup so that both editor and runtime systems consistently treat the object as unique. - Related types referenced: PlaceableObjectData, UniqueObjectData, Game.Objects.UniqueObject, PlacementFlags.