CreateEntity
Records a command to create an entity with specified archetype.
Read time 3 minutesLast updated 2 days ago
Definition
- Type: Method
- Namespace: Unity.Entities
- Assembly: UnityEngine.EntitiesModule
CreateEntity(int, EntityArchetype)
Records a command to create an entity with specified archetype.
public Entity CreateEntity(int sortKey, EntityArchetype archetype)
Parameters
A unique index for each set of commands added to this EntityCommandBuffer across all parallel jobs writing commands to this buffer. The ChunkIndexInQuery provided by IJobEntity is an appropriate value to use for this parameter. In an IJobChunk pass the 'unfilteredChunkIndex' value from IJobChunk.Execute.
The archetype of the new entity.
Returns
Type | Description |
|---|---|
| Entity | An entity that will be assigned a chunk when this EntityCommandBuffer is played back. |
Remarks
At playback, this command will throw an error if the archetype contains the Prefab tag.
CreateEntity(int)
Records a command to create an entity with no components.
public Entity CreateEntity(int sortKey)
Parameters
A unique index for each set of commands added to this EntityCommandBuffer across all parallel jobs writing commands to this buffer. The ChunkIndexInQuery provided by IJobEntity is an appropriate value to use for this parameter. In an IJobChunk pass the 'unfilteredChunkIndex' value from IJobChunk.Execute.
Returns
Type | Description |
|---|---|
| Entity | An entity that will be assigned a chunk when this EntityCommandBuffer is played back. |
CreateEntity(int, EntityArchetype, NativeArray<Entity>)
Records a command to create an array of entities with specified archetype.
public void CreateEntity(int sortKey, EntityArchetype archetype, NativeArray<Entity> entities)
Parameters
A unique index for each set of commands added to this EntityCommandBuffer across all parallel jobs writing commands to this buffer. The ChunkIndexInQuery provided by IJobEntity is an appropriate value to use for this parameter. In an IJobChunk pass the 'unfilteredChunkIndex' value from IJobChunk.Execute.
The archetype of the new entities.
An array to hold the Entity objects needed to access the new entities. The length of the array determines how many entities are created.
Remarks
At playback, this command throws an error if the archetype contains the Prefab tag.
CreateEntity(int, int, Allocator)
Records a command to create a specified number of entities with no components.
public NativeArray<Entity> CreateEntity(int sortKey, int count, Allocator allocator)
Parameters
A unique index for each set of commands added to this EntityCommandBuffer across all parallel jobs writing commands to this buffer. The ChunkIndexInQuery provided by IJobEntity is an appropriate value to use for this parameter. In an IJobChunk pass the 'unfilteredChunkIndex' value from IJobChunk.Execute.
The number of entities to create.
The allocator to use for the returned array.
Returns
Type | Description |
|---|---|
| NativeArray<Entity> | An array of the created entities. Each entity is valid immediately, but Unity doesn't assign it a chunk until the Playback method runs. |