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 |
---|---|---|
Job |
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 Entity
Examples
The following example illustrates how to use one of the default EntityAsyncProcessInfo
, and
processes each entity in the Execute()
function of an IJobProcessInfo
component and add a 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 { }
[BurstCompile]
public partial struct ProcessInBackgroundJob : IJobEntity
{
public EntityCommandBuffer.ParallelWriter ConcurrentCommands;
public void Execute(Entity entity, [ChunkIndexInQuery] int chunkIndex, in ProcessInfo info)
{
// ...hypothetical processing goes here...
// Remove ProcessInfo and add a ProcessCompleteTag...
ConcurrentCommands.RemoveComponent<ProcessInfo>(chunkIndex, entity);
ConcurrentCommands.AddComponent<ProcessCompleteTag>(chunkIndex, entity);
}
}
public partial class AsyncProcessJobSystem : SystemBase
{
protected override void OnUpdate()
{
// Get a reference to the system that will play back
var ecbSystem = World.GetOrCreateSystemManaged<NonSingletonECBSystem>();
var ecb = ecbSystem.CreateCommandBuffer();
// Pass the command buffer to the writer job, using its ParallelWriter interface
var job = new ProcessInBackgroundJob
{
ConcurrentCommands = ecb.AsParallelWriter(),
};
Dependency = job.ScheduleParallel(Dependency);
// Register the writer job with the playback system as an input dependency
ecbSystem.AddJobHandleForProducer(Dependency);
}
}