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
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 IJobForEachWithEntity<T0> Job (the
actual process is not shown since that part of the example is hypothetical). After processing, the Job
uses an EntityCommandBuffer to remove the 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 class AsyncProcessJobSystem : JobComponentSystem
{
[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 JobHandle OnUpdate(JobHandle inputDeps)
{
var job = new ProcessInBackgroundJob();
var ecbSystem =
World.GetOrCreateSystem<EndSimulationEntityCommandBufferSystem>();
job.ConcurrentCommands = ecbSystem.CreateCommandBuffer().AsParallelWriter();
var handle = job.Schedule(this, inputDeps);
ecbSystem.AddJobHandleForProducer(handle);
return handle;
}
}