# CreateCommandBuffer

> Creates an EntityCommandBuffer and adds it to this system's list of command buffers.

## Definition

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

## CreateCommandBuffer()

Creates an [EntityCommandBuffer](/engine/7000.0/script-reference/unity/entities/entitycommandbuffer.md) and adds it to this system's list of command buffers.

```csharp
public EntityCommandBuffer CreateCommandBuffer()
```

### Returns

| Type                                                                                         | Description                                            |
| -------------------------------------------------------------------------------------------- | ------------------------------------------------------ |
| [EntityCommandBuffer](/engine/7000.0/script-reference/unity/entities/entitycommandbuffer.md) | A command buffer that will be executed by this system. |

### Remarks

This buffer system executes its list of command buffers during its [EntityCommandBufferSystem.OnUpdate](/engine/7000.0/script-reference/unity/entities/entitycommandbuffersystem/onupdate.md) function in the order you created the command buffers.

This method requires a managed reference to the buffer system. To create a command buffer from unmanaged systems code, get the buffer system's `Singleton` component with [SystemAPI.GetSingleton](/engine/7000.0/script-reference/unity/entities/systemapi/getsingleton.md) and call `CreateCommandBuffer(WorldUnmanaged)` on that singleton instead.

If you write to a command buffer created by this method in a job, you must add the job as a dependency of this system by calling [EntityCommandBufferSystem.AddJobHandleForProducer](/engine/7000.0/script-reference/unity/entities/entitycommandbuffersystem/addjobhandleforproducer.md). The dependency ensures that the buffer system waits for the job to complete before executing the command buffer. This step isn't necessary for command buffers created through the buffer system's `Singleton` component, because the buffer system completes all jobs scheduled against that singleton component before it plays the command buffer back.

If you write to a command buffer from a parallel Job, such as [IJobEntity](/engine/7000.0/script-reference/unity/entities/ijobentity.md) or [IJobChunk](/engine/7000.0/script-reference/unity/entities/ijobchunk.md), you must use the concurrent version of the command buffer, provided by [EntityCommandBuffer.ParallelWriter](/engine/7000.0/script-reference/unity/entities/entitycommandbuffer/parallelwriter.md).

## CreateCommandBuffer(UnsafeList\<EntityCommandBuffer>, AllocatorHandle, WorldUnmanaged)

Creates a command buffer, sets it up, and appends it to a list of command buffers.

```csharp
public static EntityCommandBuffer CreateCommandBuffer(ref UnsafeList<EntityCommandBuffer> pendingBuffers, AllocatorManager.AllocatorHandle allocator, WorldUnmanaged world)
```

### Parameters

**** (\[UnsafeList\<EntityCommandBuffer>]\(/engine/7000.0/script-reference/unity/collections/lowlevel/unsafe/unsafelist1)): The list of command buffers to append to**** (\[AllocatorHandle]\(/engine/7000.0/script-reference/unity/collections/allocatormanager/allocatorhandle)): The allocator to allocate from, when building the command buffer**** (\[WorldUnmanaged]\(/engine/7000.0/script-reference/unity/entities/worldunmanaged)): The world that this command buffer buffers changes for

### Returns

| Type                                                                                         | Description                |
| -------------------------------------------------------------------------------------------- | -------------------------- |
| [EntityCommandBuffer](/engine/7000.0/script-reference/unity/entities/entitycommandbuffer.md) | Returns the command buffer |

## CreateCommandBuffer(UnsafeList\<EntityCommandBuffer>, WorldUnmanaged)

Creates a command buffer that allocates from a World's Update Allocator, sets it up, and appends it to a list of command buffers.

```csharp
public static EntityCommandBuffer CreateCommandBuffer(ref UnsafeList<EntityCommandBuffer> pendingBuffers, WorldUnmanaged world)
```

### Parameters

**** (\[UnsafeList\<EntityCommandBuffer>]\(/engine/7000.0/script-reference/unity/collections/lowlevel/unsafe/unsafelist1)): The list of command buffers to append to**** (\[WorldUnmanaged]\(/engine/7000.0/script-reference/unity/entities/worldunmanaged)): The world that this command buffer buffers changes for

### Returns

| Type                                                                                         | Description                |
| -------------------------------------------------------------------------------------------- | -------------------------- |
| [EntityCommandBuffer](/engine/7000.0/script-reference/unity/entities/entitycommandbuffer.md) | Returns the command buffer |
