Skip to content

Game.Prefabs.MovingObjectData

Assembly: Game
Namespace: Game.Prefabs

Type: struct

Base: IComponentData, IQueryTypeParameter, IEmptySerializable

Summary:
A small component that stores an EntityArchetype used for "stopped" variants of moving objects. This struct acts as a lightweight container / cache so systems managing moving objects can reuse a pre-created archetype when converting or spawning stopped objects, avoiding repeated CreateArchetype calls. It implements IQueryTypeParameter to be usable in queries and IEmptySerializable to participate in the game's custom serialization pipeline where applicable.


Fields

  • public EntityArchetype m_StoppedArchetype
    Holds the Unity.Entities.EntityArchetype that represents the component layout used for stopped objects. Typically created once (via EntityManager.CreateArchetype) and stored here so systems can create or convert entities using this archetype quickly. Note: an EntityArchetype is tied to a specific EntityManager; recreate archetypes after world/EntityManager changes (e.g., domain reload or world recreation).

  • (No other fields)

Properties

  • None.
    This is a plain struct used as component data; it exposes a single public field rather than properties.

Constructors

  • public MovingObjectData()
    Default value-type constructor (implicit). In typical use you explicitly set m_StoppedArchetype after creating the archetype.

Methods

  • None.
    This component contains only data; systems operate on it via the EntityManager / ECS systems.

Usage Example

// Example inside a System or initialization code with access to EntityManager
protected override void OnCreate()
{
    base.OnCreate();

    // Create an archetype that represents the stopped object layout
    var stoppedArchetype = EntityManager.CreateArchetype(
        typeof(Translation),
        typeof(Rotation),
        typeof(SomeStoppedTag) // replace with actual components used for stopped objects
    );

    // Create a singleton entity to hold the archetype for reuse
    var singleton = EntityManager.CreateEntity(typeof(MovingObjectData));
    EntityManager.SetComponentData(singleton, new MovingObjectData
    {
        m_StoppedArchetype = stoppedArchetype
    });
}

// Later, when converting or spawning a stopped object:
var movingData = EntityManager.GetComponentData<MovingObjectData>(singleton);
Entity stoppedEntity = EntityManager.CreateEntity(movingData.m_StoppedArchetype);
// populate instance-specific components on the created entity as needed

Notes and best practices: - Cache the archetype once on world/system creation to avoid frequent CreateArchetype overhead. - Remember that EntityArchetype values are only valid for the EntityManager that created them; they should be recreated if the world or EntityManager is recreated. - This struct is intended to be plain data; all behavior belongs in systems that read this component.