To ensure correct behavior of other systems, the job or a dependency must be assigned...

I get:

The system Unity.Physics.Systems.BuildPhysicsWorld reads Unity.Entities.Entity via Jobs:CreateRigidBodies 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.

If I attempt to do some casual Physics Queries single-threaded from within a SystemBase OnUpdate() method.

Just in case I do:

    protected override void OnStartRunning()
    {
        base.OnStartRunning();
        this.RegisterPhysicsRuntimeSystemReadOnly();
    }

And OnUpdate:

    protected override void OnUpdate()
    {
        //var ecb = World.GetExistingSystem<BeginSimulationEntityCommandBufferSystem>().CreateCommandBuffer();
        var world = World.GetExistingSystem<BuildPhysicsWorld>().PhysicsWorld.CollisionWorld;

        var filter = new CollisionFilter()
        {
            BelongsTo = ~0u,
            CollidesWith = ~0u,
            GroupIndex = 0
        };

        var distanceInput = new PointDistanceInput()
        {
            Position = new float3(0, 0, 0),// agent.PathEnd,
            MaxDistance = 0.25f,
            Filter = filter
        };

        world.CalculateDistance(distanceInput, out DistanceHit hit);

    }

…But no luck, throws an error each time. I was sure it was working before though. I spend substantial time on this stuff now so it’s all kind of a blur… help!

It’s because you’re doing it on mainthread instead of in a job - if you schedule this into a job it’d work fine. If you want this to work on mainthread you need to do Dependency.Complete()

1 Like

Strange:

        collisionWorld.CalculateDistance(distanceInput, out DistanceHit hit);
        Dependency.Complete();

But still same error.

Hmm I see:

    protected override void OnUpdate()
    {
        Dependency.Complete();

I should do it before as the dependency doesn’t follow but is before I cast.

I tried:

[UpdateInGroup(typeof(FixedStepSimulationSystemGroup))]
[UpdateBefore(typeof(BuildPhysicsWorld))]

On the System, but that’s not good enough and it only runs if I do the above.

I usually get this error when in other system I read from something but is not tagged with the [ReadOnly] attribute.

1 Like

Yes you need to do it before because the other jobs could still be running when this system updates.

If you did this in a job instead (job with code etc) then it’d simply schedule the job after the dependency was complete.

1 Like

Not sure what I was thinking. I didn’t do much with Jobs before coming to Entities!