Method AddJobHandleForProducer
AddJobHandleForProducer(JobHandle)
Adds the specified JobHandle to this system's list of dependencies.
Declaration
public void AddJobHandleForProducer(JobHandle producerJob)
Parameters
Type | Name | Description |
---|---|---|
JobHandle | 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 a command buffer from a Job, you must add the JobHandle of that Job to this buffer system's dependency list by calling this function. Otherwise, the buffer system could execute the commands currently in the command buffer while the writing Job is still in progress.
Examples
The following example illustrates how to use one of the default EntityCommandBuffer systems.
The code selects all entities that have one custom component, in this case, AsyncProcessInfo
, and
processes each entity in the Execute()
function of an ProcessInfo
component and add an ProcessCompleteTag
component. Another system could use the ProcessCompleteTag
to find entities that represent the end
results of the process.
public struct ProcessInfo: IComponentData{ public float Value; }
public struct ProcessCompleteTag : IComponentData{}
public partial class AsyncProcessJobSystem : SystemBase
{
[BurstCompile]
public struct ProcessInBackgroundJob : IJobForEachWithEntity<ProcessInfo>
{
[ReadOnly]
public EntityCommandBuffer.ParallelWriter ConcurrentCommands;
public void Execute(Entity entity, int index, [ReadOnly] ref ProcessInfo info)
{
// Process based on the ProcessInfo component,
// then remove ProcessInfo and add a ProcessCompleteTag...
ConcurrentCommands.RemoveComponent<ProcessInfo>(index, entity);
ConcurrentCommands.AddComponent(index, entity, new ProcessCompleteTag());
}
}
protected override void OnUpdate()
{
var job = new ProcessInBackgroundJob();
var ecbSystem =
World.GetOrCreateSystem<EndSimulationEntityCommandBufferSystem>();
job.ConcurrentCommands = ecbSystem.CreateCommandBuffer().AsParallelWriter();
Dependency = job.Schedule(this, Dependency);
ecbSystem.AddJobHandleForProducer(Dependency);
}
}