Unity Physics PhysicsBody set to Dynamic or Kinematic on a NavAgent causes NavSurfaceTrackingJob to throw errors
See original GitHub issueIf the GameObject that NavAgent is added to when converted to an entity contains a PhysicsBody script anywhere in its hierarchy that has its Motion Type set to Dynamic or Kinematic when it is converted via ConvertEntity, an InvalidOperationException is thrown each frame complaining about unsafe reading from the Unity.Physics.MotionData NativeArray. The error is not thrown when Motion Type is set to Static.
To reproduce: Open the ReeseUnityDemos project Find the DinosaurPrefab prefab Add the PhysicsBody script to the prefab and set Motion Type to Static Click Play and verify that the scene plays as normal Stop the scene and change Motion Type to Dynamic or Kinematic on the DinosaurPrefab prefab Click Play and see the InvalidOperationException error
You get the same result with Unity Physics v0.3.2 and v0.4.0.
Stack trace of the error:
InvalidOperationException: The previously scheduled job NavSurfaceSystem:<>c__DisplayClass_NavSurfaceTrackingJob reads from the NativeArray <>c__DisplayClass_NavSurfaceTrackingJob.JobData.physicsWorld.DynamicsWorld.m_MotionVelocities. You are trying to schedule a new job Solver:ParallelApplyGravityAndCopyInputVelocitiesJob, which writes to the same NativeArray (via ParallelApplyGravityAndCopyInputVelocitiesJob.MotionVelocities). To guarantee safety, you must include NavSurfaceSystem:<>c__DisplayClass_NavSurfaceTrackingJob as a depen
Unity.Jobs.LowLevel.Unsafe.JobsUtility.ScheduleParallelFor (Unity.Jobs.LowLevel.Unsafe.JobsUtility+JobScheduleParameters& parameters, System.Int32 arrayLength, System.Int32 innerloopBatchCount) (at <3dc54541a2574ac7826a004a212a4332>:0)
Unity.Jobs.IJobParallelForExtensions.Schedule[T] (T jobData, System.Int32 arrayLength, System.Int32 innerloopBatchCount, Unity.Jobs.JobHandle dependsOn) (at <3dc54541a2574ac7826a004a212a4332>:0)
Unity.Physics.Solver.ScheduleApplyGravityAndCopyInputVelocitiesJob (Unity.Collections.NativeArray`1[T] motionVelocities, Unity.Collections.NativeArray`1[T] inputVelocities, Unity.Mathematics.float3 gravityAcceleration, Unity.Jobs.JobHandle inputDeps, System.Int32 threadCountHint) (at Library/PackageCache/com.unity.physics@0.4.0-preview.5/Unity.Physics/Dynamics/Solver/Solver.cs:167)
Unity.Physics.Simulation.ScheduleStepJobs (Unity.Physics.SimulationStepInput input, Unity.Physics.SimulationCallbacks callbacksIn, Unity.Jobs.JobHandle inputDeps, System.Int32 threadCountHint) (at Library/PackageCache/com.unity.physics@0.4.0-preview.5/Unity.Physics/Dynamics/Simulation/Simulation.cs:363)
Unity.Physics.Systems.StepPhysicsWorld.OnUpdate () (at Library/PackageCache/com.unity.physics@0.4.0-preview.5/Unity.Physics/ECS/Systems/StepPhysicsWorld.cs:100)
Unity.Entities.SystemBase.Update () (at Library/PackageCache/com.unity.entities@0.11.1-preview.4/Unity.Entities/SystemBase.cs:414)
Unity.Entities.ComponentSystemGroup.UpdateAllSystems () (at Library/PackageCache/com.unity.entities@0.11.1-preview.4/Unity.Entities/ComponentSystemGroup.cs:445)
UnityEngine.Debug:LogException(Exception)
Unity.Debug:LogException(Exception) (at Library/PackageCache/com.unity.entities@0.11.1-preview.4/Unity.Entities/Stubs/Unity/Debug.cs:19)
Unity.Entities.ComponentSystemGroup:UpdateAllSystems() (at Library/PackageCache/com.unity.entities@0.11.1-preview.4/Unity.Entities/ComponentSystemGroup.cs:450)
Unity.Entities.ComponentSystemGroup:OnUpdate() (at Library/PackageCache/com.unity.entities@0.11.1-preview.4/Unity.Entities/ComponentSystemGroup.cs:398)
Unity.Entities.ComponentSystem:Update() (at Library/PackageCache/com.unity.entities@0.11.1-preview.4/Unity.Entities/ComponentSystem.cs:109)
Unity.Entities.DummyDelegateWrapper:TriggerUpdate() (at Library/PackageCache/com.unity.entities@0.11.1-preview.4/Unity.Entities/ScriptBehaviourUpdateOrder.cs:192)
Issue Analytics
- State:
- Created 3 years ago
- Comments:6 (3 by maintainers)
Top GitHub Comments
Patched in
nav/v0.10.3
. How you want to handle gravity is up to you—I zeroed it in my testing. If you experience other problems, please submit more issues. Hopefully this change helps.Edit: FYI, it was just a simple change to the system update order as expected.
@Mdlich It may well be possible that some upgrading is due. I’ve been busy working on my own game, so I’ve neglected this project for the past couple weeks. Like I said, the core issue here is probably system update order. I’ll get back to you within the next couple days.