# CreateEntity

> Records a command to create an entity with specified archetype.

## Definition

* **Type:** Method
* **Namespace:** [Unity.Entities](/engine/7000.0/script-reference/unity/entities.md)
* **Assembly:** UnityEngine.EntitiesModule

## CreateEntity(int, EntityArchetype)

Records a command to create an entity with specified archetype.

```csharp
public Entity CreateEntity(int sortKey, EntityArchetype archetype)
```

### Parameters

**** (\[int]\(https\://learn.microsoft.com/dotnet/api/system.int32)): A unique index for each set of commands added to this EntityCommandBuffer across all parallel jobs writing commands to this buffer. The [ChunkIndexInQuery](/engine/7000.0/script-reference/unity/entities/chunkindexinquery.md) provided by [IJobEntity](/engine/7000.0/script-reference/unity/entities/ijobentity.md) is an appropriate value to use for this parameter. In an [IJobChunk](/engine/7000.0/script-reference/unity/entities/ijobchunk.md) pass the 'unfilteredChunkIndex' value from IJobChunk.Execute.**** (\[EntityArchetype]\(/engine/7000.0/script-reference/unity/entities/entityarchetype)): The archetype of the new entity.

### Returns

| Type                                                               | Description                                                                           |
| ------------------------------------------------------------------ | ------------------------------------------------------------------------------------- |
| [Entity](/engine/7000.0/script-reference/unity/entities/entity.md) | 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](/engine/7000.0/script-reference/unity/entities/prefab.md) tag.

## CreateEntity(int)

Records a command to create an entity with no components.

```csharp
public Entity CreateEntity(int sortKey)
```

### Parameters

**** (\[int]\(https\://learn.microsoft.com/dotnet/api/system.int32)): A unique index for each set of commands added to this EntityCommandBuffer across all parallel jobs writing commands to this buffer. The [ChunkIndexInQuery](/engine/7000.0/script-reference/unity/entities/chunkindexinquery.md) provided by [IJobEntity](/engine/7000.0/script-reference/unity/entities/ijobentity.md) is an appropriate value to use for this parameter. In an [IJobChunk](/engine/7000.0/script-reference/unity/entities/ijobchunk.md) pass the 'unfilteredChunkIndex' value from IJobChunk.Execute.

### Returns

| Type                                                               | Description                                                                           |
| ------------------------------------------------------------------ | ------------------------------------------------------------------------------------- |
| [Entity](/engine/7000.0/script-reference/unity/entities/entity.md) | 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.

```csharp
public void CreateEntity(int sortKey, EntityArchetype archetype, NativeArray<Entity> entities)
```

### Parameters

**** (\[int]\(https\://learn.microsoft.com/dotnet/api/system.int32)): A unique index for each set of commands added to this EntityCommandBuffer across all parallel jobs writing commands to this buffer. The [ChunkIndexInQuery](/engine/7000.0/script-reference/unity/entities/chunkindexinquery.md) provided by [IJobEntity](/engine/7000.0/script-reference/unity/entities/ijobentity.md) is an appropriate value to use for this parameter. In an [IJobChunk](/engine/7000.0/script-reference/unity/entities/ijobchunk.md) pass the 'unfilteredChunkIndex' value from IJobChunk.Execute.**** (\[EntityArchetype]\(/engine/7000.0/script-reference/unity/entities/entityarchetype)): The archetype of the new entities.**** (\[NativeArray\<Entity>]\(/engine/7000.0/script-reference/unity/collections/nativearray1)): 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](/engine/7000.0/script-reference/unity/entities/prefab.md) tag.

## CreateEntity(int, int, Allocator)

Records a command to create a specified number of entities with no components.

```csharp
public NativeArray<Entity> CreateEntity(int sortKey, int count, Allocator allocator)
```

### Parameters

**** (\[int]\(https\://learn.microsoft.com/dotnet/api/system.int32)): A unique index for each set of commands added to this EntityCommandBuffer across all parallel jobs writing commands to this buffer. The [ChunkIndexInQuery](/engine/7000.0/script-reference/unity/entities/chunkindexinquery.md) provided by [IJobEntity](/engine/7000.0/script-reference/unity/entities/ijobentity.md) is an appropriate value to use for this parameter. In an [IJobChunk](/engine/7000.0/script-reference/unity/entities/ijobchunk.md) pass the 'unfilteredChunkIndex' value from IJobChunk.Execute.**** (\[int]\(https\://learn.microsoft.com/dotnet/api/system.int32)): The number of entities to create.**** (\[Allocator]\(/engine/7000.0/script-reference/unity/collections/allocator)): The allocator to use for the returned array.

### Returns

| Type                                                                                      | Description                                                                                                                             |
| ----------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------- |
| [NativeArray\<Entity>](/engine/7000.0/script-reference/unity/collections/nativearray1.md) | An array of the created entities. Each entity is valid immediately, but Unity doesn't assign it a chunk until the Playback method runs. |
