Method CreateEntity
CreateEntity(int, EntityArchetype)
Records a command to create an entity with specified archetype.
Declaration
public Entity CreateEntity(int sortKey, EntityArchetype archetype)
Parameters
| Type | Name | Description |
|---|---|---|
| int | sortKey | 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 Execute(in ArchetypeChunk, int, bool, in v128). |
| EntityArchetype | archetype | 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.
Exceptions
| Type | Condition |
|---|---|
| ArgumentException | Throws if the archetype is null. |
| NullReferenceException | Throws if an Allocator was not passed in when the EntityCommandBuffer was created. |
CreateEntity(int)
Records a command to create an entity with no components.
Declaration
public Entity CreateEntity(int sortKey)
Parameters
| Type | Name | Description |
|---|---|---|
| int | sortKey | 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 Execute(in ArchetypeChunk, int, bool, in v128). |
Returns
| Type | Description |
|---|---|
| Entity | An entity that will be assigned a chunk when this EntityCommandBuffer is played back. |
Exceptions
| Type | Condition |
|---|---|
| NullReferenceException | Throws if an Allocator was not passed in when the EntityCommandBuffer was created. |
CreateEntity(int, EntityArchetype, NativeArray<Entity>)
Records a command to create an array of entities with specified archetype.
Declaration
public void CreateEntity(int sortKey, EntityArchetype archetype, NativeArray<Entity> entities)
Parameters
| Type | Name | Description |
|---|---|---|
| int | sortKey | 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 Execute(in ArchetypeChunk, int, bool, in v128). |
| EntityArchetype | archetype | The archetype of the new entities. |
| NativeArray<Entity> | 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.
Exceptions
| Type | Condition |
|---|---|
| NullReferenceException | Throws if an Allocator was not passed in when the EntityCommandBuffer was created. |
CreateEntity(int, int, Allocator)
Records a command to create a specified number of entities with no components.
Declaration
public NativeArray<Entity> CreateEntity(int sortKey, int count, Allocator allocator)
Parameters
| Type | Name | Description |
|---|---|---|
| int | sortKey | 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 Execute(in ArchetypeChunk, int, bool, in v128). |
| int | count | The number of entities to create. |
| Allocator | allocator | 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. |
Exceptions
| Type | Condition |
|---|---|
| NullReferenceException | Throws if an Allocator was not passed in when the EntityCommandBuffer was created. |