Version: Unity 7.0 Alpha (7000.0)
LanguageEnglish
  • C#

EntityCommandBufferSystem

class in Unity.Entities

/

Inherits from:Unity.Entities.SystemBase

Suggest a change

Success!

Thank you for helping us improve the quality of Unity Documentation. Although we cannot accept all submissions, we do read each suggested change from our users and will make updates where applicable.

Close

Submission failed

For some reason your suggested change could not be submitted. Please <a>try again</a> in a few minutes. And thank you for taking the time to help us improve the quality of Unity Documentation.

Close

Cancel

Description

A system that provides EntityCommandBuffer objects for other systems.

Each system that uses the EntityCommandBuffer provided by a command buffer system must 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 EntityCommandBufferSystem.OnUpdate function.

To create a command buffer, get the buffer system's Singleton component with SystemAPI.GetSingleton, and then call CreateCommandBuffer(WorldUnmanaged) on that singleton. If you write to a command buffer created this way from a Job, you don't need to register that Job with the buffer system: the buffer system completes all Jobs scheduled against its singleton component before it plays the command buffer back.

If you instead call EntityCommandBufferSystem.CreateCommandBuffer on the buffer system instance, and you write to that command buffer from a Job, you must add the JobHandle of that Job to the buffer system's dependency list with EntityCommandBufferSystem.AddJobHandleForProducer.

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 (ParallelWriter).

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.

Public Methods

Method Description
AddJobHandleForProducer 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.

Protected Methods

Method Description
OnCreate Initializes this command buffer system.
OnDestroy Destroys this system. Any pending command buffers will be disposed, but their commands will NOT be played back.
OnUpdate Executes the command buffers in this system in the order they were created.

Inherited Members

Properties

PropertyDescription
Enabled Controls whether this system executes when its OnUpdate function is called.
EntityManager The EntityManager object of the ComponentSystemBase.World in which this system exists.
EntityQueries The query objects cached by this system.
GlobalSystemVersion The current change version number in this ComponentSystemBase.World.
LastSystemVersion The current version of this system.
SystemHandle The SystemHandle of this system.
World The World in which this system exists.
WorldUpdateAllocator Retrieve world update allocator from system state.
CheckedStateRef The SystemState for this SystemBase.
Dependency The ECS-related data dependencies of the system.

Public Methods

MethodDescription
GetBufferTypeHandle Manually gets the run-time type information required to access an array of buffer components in a chunk.
GetComponentTypeHandle Manually gets the run-time type information required to access an array of component data in a chunk.
GetDynamicComponentTypeHandle Manually gets the run-time type information required to access an array of component data in a chunk.
GetDynamicSharedComponentTypeHandle Manually gets the run-time type information required to access a shared component data in a chunk.
GetEntityQuery Gets the cached query for the specified component types, if one exists; otherwise, creates a new query instance and caches it.
GetEntityTypeHandle Manually gets the run-time type information required to access the array of Entity objects in a chunk.
GetSharedComponentTypeHandle Manually gets the run-time type information required to access a shared component data in a chunk.
RequireAnyForUpdate Provide a set of queries, one of which must match entities for the system to run.
RequireForUpdate Adds a query that must match entities for the system to run. You can add multiple required queries to a system; all of them must match at least one entity for the system to run.
ShouldRunSystem Reports whether this system satisfies the criteria to update. This function is used internally to determine whether the system's OnUpdate function can be skipped.
GetBufferLookup Manually gets a BufferLookup<T> object that can access a DynamicBuffer<T0>.
GetComponentLookup Manually gets a dictionary-like container containing all components of type T, keyed by Entity.
GetEntityStorageInfoLookup Manually gets an EntityStorageInfoLookup object that can access a EntityStorageInfo.
Update Update the system manually.

Protected Methods

MethodDescription
OnStartRunning Called before the first call to OnUpdate and when a system resumes updating after being stopped or disabled.
OnStopRunning Called when this system stops running because no entities match the system's EntityQuery objects or because you change the system ComponentSystemBase.Enabled property to false.
CompleteDependency Completes job handles registered with this system. See SystemBase.Dependency for more information.
HasBuffer Checks whether an entity has a dynamic buffer of a specific IBufferElementData type.