#ISystem, ScheduleParallel, ECB and 'complex' Dependancies

1 messages · Page 1 of 1 (latest)

wind charm
#

Hello,

I'm trying to set up a job dependancy within a parallel job system for a RTS-like game

[BurstCompile]
public void OnUpdate(ref SystemState state)
{
    var spatial = SystemAPI.GetSingleton<AgentSpatialPartitioningSystem.Singleton>();

    EntityCommandBuffer ecb = new EntityCommandBuffer(Allocator.TempJob);
    EntityCommandBuffer.ParallelWriter parallelEcb = ecb.AsParallelWriter();

    m_UnitLookup.Update(ref state);
    m_TransformLookup.Update(ref state);

    JobHandle idleJob = new Jobs.SwarmUnitBrainIdleJob()
        .ScheduleParallel(state.Dependency);

    JobHandle moveJob = new Jobs.SwarmUnitBrainMoveJob()
        .ScheduleParallel(state.Dependency);

    JobHandle sightJob = new Jobs.SwarmUnitBrainEnnemySight {
        CharacterLookup = m_UnitLookup,
        Spatial = spatial
    }.ScheduleParallel(state.Dependency);

    JobHandle addFollowEnnemy = new Jobs.SwarmUnitStartFollowingEnnemyOnSightJob {
        Ecb = parallelEcb
    }.ScheduleParallel(sightJob);

    JobHandle updateFollowEnnemy = new Jobs.SwarmUnitUpdateFollowingEnnemyToSightedJob {
        Ecb = parallelEcb
    }.ScheduleParallel(sightJob);

    JobHandle followDecisionHandle = JobHandle.CombineDependencies(
        addFollowEnnemy, updateFollowEnnemy);

    JobHandle followEnnemyJob = new Jobs.SwarmUnitBrainFollowingEnnemyJob {
        Ecb = parallelEcb,
        TransformLookup = m_TransformLookup
    }.ScheduleParallel(followDecisionHandle);

    JobHandle attackJob = new Jobs.SwarmUnitBrainAttackJob {
        Ecb = parallelEcb 
    }.ScheduleParallel(followDecisionHandle);

    NativeArray<JobHandle> deps = new NativeArray<JobHandle>(new JobHandle[]{
        idleJob,
        moveJob,
        followEnnemyJob,
        attackJob
    }, Allocator.Temp);

    state.Dependency = JobHandle.CombineDependencies(deps);

    ecb.Playback(state.EntityManager);
    ecb.Dispose();

}```
#

Thing is, now I setted the dependancy system, I get some errors each frame stating I haven't setted dependencies

#

The system Dots.Systems.SwarmUnitBrainSystem reads Dots.Components.CharacterComponent via SwarmUnitBrainEnnemySight but that type was not assigned to the Dependency property. To ensure correct behavior of other systems, the job or a dependency must be assigned to the Dependency property before returning from the OnUpdate method.

#

InvalidOperationException: The previously scheduled job SwarmUnitBrainIdleJob writes to the Unity.Entities.EntityCommandBuffer SwarmUnitBrainIdleJob.JobData.Ecb. You are trying to schedule a new job SwarmUnitStartFollowingEnnemyOnSightJob, which writes to the same Unity.Entities.EntityCommandBuffer (via SwarmUnitStartFollowingEnnemyOnSightJob.JobData.Ecb). To guarantee safety, you must include SwarmUnitBrainIdleJob as a dependency of the newly scheduled job.

#

The system Dots.Systems.SwarmUnitBrainSystem writes Dots.Components.SwarmUnitSightingForEnnemiesComponent via SwarmUnitStartFollowingEnnemyOnSightJob but that type was not assigned to the Dependency property. To ensure correct behavior of other systems, the job or a dependency must be assigned to the Dependency property before returning from the OnUpdate method.

#

InvalidOperationException: The previously scheduled job SwarmUnitBrainAttackJob writes to the Unity.Entities.EntityCommandBuffer SwarmUnitBrainAttackJob.JobData.Ecb. You must call JobHandle.Complete() on the job SwarmUnitBrainAttackJob, before you can write to the Unity.Entities.EntityCommandBuffer safely.

#

I'm unsure whether is case is supported or not

#

Or is there something I missed ? Is there something to declare for Ecb ?

#

ISystem, ScheduleParallel, ECB and 'complex' Dependancies

faint stone
#

you didn't manage your dependencies

#

good enough, so some jobs access same components

#

while scheduled without dependency on each other

#

why are you trying to manage them manually? You can just create system per job

#

and mantain order with UpdateBefore/After attributes

#

you also can't pass same ecb to multiple non-sequential jobs

#

you'd need to disable safety for it if you really want it this way

wind charm
wind charm
faint stone
#

within same system no

#

you try to run all your jobs in paralle

#

but that seems like it's unsafe

#

since they access same components

wind charm
#

I don't think my jobs are actually accessing the same components (with the constraint they have)
this is why I wanted to parallelized them

faint stone
#

exceptions tell you exactly what data is accessed between same jobs

wind charm
#

The code I use is inspired from ProjectDawn.Navigation.Sample.Zerg.UnitBrainSystem if you have the package
They don't use parallelizedEcb nor dependancy constraint, though

faint stone
#

if you are absolutely sure that chain is safe

#

you can simply disable safety for whole job

#

but if game crashes - that's on you