Class EntityCommandBufferSystem
A system that provides EntityCommandBuffer objects for other systems.
Inherited Members
Namespace: Unity.Entities
Syntax
public abstract class EntityCommandBufferSystem : SystemBase
Remarks
Each system that uses the EntityCommandBuffer provided by a command buffer system must call CreateCommandBuffer() to create its own command buffer instance. This buffer system executes each of these separate command buffers in the order that you created them. The commands are executed during this system's OnUpdate() function.
When you write to a command buffer from a Job, you must add the JobHandle of that Job to the buffer system's dependency list with AddJobHandleForProducer(JobHandle).
If you write to a command buffer from a Job that runs in parallel (and this includes both IJobEntity and IJobChunk), you must use the concurrent version of the command buffer (AsParallelWriter()).
Executing the commands in an EntityCommandBuffer invokes the corresponding functions of the EntityManager. Any structural change, such as adding or removing entities, adding or removing components from entities, or changing shared component values, creates a sync-point in your application. At a sync point, all Jobs accessing entity components must complete before new Jobs can start. Such sync points make it difficult for the Job scheduler to fully utilize available computing power. To avoid sync points, you should use as few entity command buffer systems as possible.
The default ECS World code creates a ComponentSystemGroup setup with three main groups, InitializationSystemGroup, SimulationSystemGroup, and PresentationSystemGroup. Each of these main groups provides an existing EntityCommandBufferSystem executed at the start and the end of other, child systems.
Note that unused command buffers systems do not create sync points because there are no commands to execute and thus no structural changes created.
The EntityCommandBufferSystem class is abstract, so you must implement a subclass to create your own entity command buffer system. However, none of its methods are abstract, so you do not need to implement your own logic. Typically, you create an EntityCommandBufferSystem subclass to create a named buffer system for other systems to use and update it at an appropriate place in a custom ComponentSystemGroup setup.
Fields
Name | Description |
---|---|
m_PendingBuffers | List of command buffers that this system has allocated, which are played back and disposed of when the system updates. |
Properties
Name | Description |
---|---|
PendingBuffers |
Methods
Name | Description |
---|---|
AddJobHandleForProducer(JobHandle) | Adds the specified JobHandle to this system's list of dependencies. |
CreateCommandBuffer() | Creates an EntityCommandBuffer and adds it to this system's list of command buffers. |
CreateCommandBuffer(ref UnsafeList<EntityCommandBuffer>, AllocatorManager.AllocatorHandle, WorldUnmanaged) | Creates a command buffer, sets it up, and appends it to a list of command buffers. |
CreateCommandBuffer(ref 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. |
OnCreate() | Initializes this command buffer system. |
OnDestroy() | Destroys this system, executing any pending command buffers first. |
OnUpdate() | Executes the command buffers in this system in the order they were created. |