question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Unity Physics PhysicsBody set to Dynamic or Kinematic on a NavAgent causes NavSurfaceTrackingJob to throw errors

See original GitHub issue

If 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:closed
  • Created 3 years ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
reeseschultzcommented, Jul 11, 2020

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.

1reaction
reeseschultzcommented, Jul 11, 2020

@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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

NavMeshAgent acts weird after responding to Physics
The enemy seems to still path find, but to some odd location, or it shudders and moves sporadically. If I make the enemy...
Read more >
Using NavMesh Agent with Other Components
Kinematic means that the rigid body is controlled by something else than the physics simulation. If both NavMesh Agent and Rigidbody (non-kinematic) are ......
Read more >
How do I fix the IndexOutOfRangeException caused by ...
Try restarting Unity. It's a Unity error that you can do nothing about. You could follow the suggestion (Turn off burst (Jobs →...
Read more >
NavMesh Obstacle
Unity treats the Nav Mesh Obstacle as moving when it has moved more than the distance set by the Move Threshold. Use this...
Read more >
A warning to professionals considering unity for large ...
Unity implies that it's kinematic physics object work with non-kinematic ... The Navmesh system supports static and dynamic obstacles.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found