Documentation

Unity Engine


Unity Engine


AddJobHandleForProducer(JobHandle)

Adds the specified JobHandle to this system's list of dependencies.
Read time 1 minuteLast updated a day ago

Definition

  • Type: Method
  • Namespace: Unity.Entities
  • Assembly: UnityEngine.EntitiesModule
public void AddJobHandleForProducer(JobHandle producerJob)

Parameters

producerJob

The JobHandle of a Job which this buffer system should wait for before playing back its pending command buffers.

Remarks

When you write to an EntityCommandBuffer that you created with EntityCommandBufferSystem.CreateCommandBuffer from a job, you must add the JobHandle of that job to this EntityCommandBufferSystem input dependencies by calling this function. Otherwise, this system could attempt to execute the command buffer contents while the writing job is still running, causing a race condition.
Don't call this function for command buffers that you created through the buffer system's
Singleton
component. Those command buffers are tracked through the singleton component itself, and this system completes all jobs scheduled against that component before it plays the command buffers back.
The following example illustrates how to use one of the default EntityCommandBufferSystems. The code selects all entities that have one custom component, in this case,
AsyncProcessInfo
, and processes each entity in the
Execute()
function of an IJobEntity Job. After processing, the Job uses a EntityCommandBuffer to remove the
ProcessInfo
component and add a
ProcessCompleteTag
component. Another system could use the
ProcessCompleteTag
to find entities that represent the end results of the process.