Property Dependency
Dependency
The ECS-related data dependencies of the system.
Declaration
protected JobHandle Dependency { get; set; }
Property Value
Type | Description |
---|---|
Job |
Remarks
Before On
The following example illustrates an OnUpdate()
implementation that relies on implicit dependency
management. The function schedules three jobs, each depending on the previous one:
protected override void OnUpdate()
{
Entities
.WithName("ForEach_Job_One")
.ForEach((ref AComponent c) =>
{
/*...*/
})
.ScheduleParallel();
Entities
.WithName("ForEach_Job_Two")
.ForEach((ref AnotherComponent c) =>
{
/*...*/
})
.ScheduleParallel();
NativeArray<int> result = new NativeArray<int>(1, Allocator.TempJob);
Job
.WithName("Job_Three")
.WithDisposeOnCompletion(result)
.WithCode(() =>
{
/*...*/
result[0] = 1;
})
.Schedule();
}
You can opt out of this default dependency management by explicitly passing a JobHandle to
Entities.
The following On
protected override void OnUpdate()
{
JobHandle One = Entities
.WithName("ForEach_Job_One")
.ForEach((ref AComponent c) =>
{
/*...*/
})
.ScheduleParallel(this.Dependency);
JobHandle Two = Entities
.WithName("ForEach_Job_Two")
.ForEach((ref AnotherComponent c) =>
{
/*...*/
})
.ScheduleParallel(this.Dependency);
JobHandle intermediateDependencies =
JobHandle.CombineDependencies(One, Two);
NativeArray<int> result = new NativeArray<int>(1, Allocator.TempJob);
JobHandle finalDependency = Job
.WithName("Job_Three")
.WithDisposeOnCompletion(result)
.WithCode(() =>
{
/*...*/
result[0] = 1;
})
.Schedule(intermediateDependencies);
this.Dependency = finalDependency;
}
You can combine implicit and explicit dependency management (by using JobHandle.CombineDependencies); however, doing so can be error prone. When you set the Dependency property, the assigned JobHandle replaces any existing dependency, it is not combined with them.
Note that the default, implicit dependency management does not include IJob