Game.ObjectData
Assembly: Game
Namespace: Game.Prefabs
Type: struct
Base: IComponentData, IQueryTypeParameter, IEmptySerializable
Summary:
Represents a small component used by the prefab/object system to store an EntityArchetype reference. This struct is intended to be attached to an Entity that represents a prefab or template; the m_Archetype field holds an archetype describing the component layout for entities that should be instantiated from that prefab. It implements IComponentData so it can be stored as an ECS component, IQueryTypeParameter to be usable in queries, and IEmptySerializable to participate in the game's custom serialization pipeline.
Fields
public Unity.Entities.EntityArchetype m_Archetype
Holds the Unity.Entities.EntityArchetype that describes the component composition for entities created from this prefab. Archetype handles are only valid within the lifetime of the EntityManager/World that created them; do not assume they remain meaningful across save/load or different worlds.
Properties
- This type has no properties.
Constructors
public ObjectData()
Structs have an implicit parameterless constructor. Initialize m_Archetype explicitly before use. Example:new ObjectData { m_Archetype = someArchetype }
.
Methods
- This type declares no methods.
Usage Example
// Example: create an archetype and store it in an entity as ObjectData
var em = World.DefaultGameObjectInjectionWorld.EntityManager;
// Create an archetype describing the components for spawned instances
var instanceArchetype = em.CreateArchetype(
typeof(Unity.Transforms.LocalToWorld),
typeof(MyCustomComponent)
);
// Create a prefab/entity that stores the archetype reference
var prefabEntity = em.CreateEntity();
em.AddComponentData(prefabEntity, new Game.Prefabs.ObjectData {
m_Archetype = instanceArchetype
});
// Later, when instantiating instances, use the stored archetype with the same EntityManager
var instance = em.CreateEntity(em.GetComponentData<Game.Prefabs.ObjectData>(prefabEntity).m_Archetype);
Notes and warnings: - EntityArchetype is a runtime handle tied to a specific EntityManager/World. Do not attempt to persist the archetype across sessions; instead recreate archetypes at runtime when needed. - Because this is a plain ECS component, use the EntityManager APIs on the main thread, or appropriate entity command buffers when creating entities from jobs.