How do I get NavMeshAgents not to walk through objects?

Hey, everyone! This is my first question on the Unity Forums!

So, I have a NavMeshAgent attached to a player-controlled unit. When the player clicks a valid target, the unit moves towards that target on the NavMesh. However, if I try to give it a target on the other side of an obstacle, the agent just goes right through it! I’ve messed with colliders, rigidbodies, and isKinematic, but to no avail.


You need to add a nav mesh obstacle component to your non-static objects.

For your obstacle, try

  1. Going to navigation tab

  2. Go to the object tab of the navigation tab

  3. Select Navigation Static

  4. Go to Navigation Area change Walkable to Not Walkable

  5. Click Bake (Rebake the NavMesh)

On The Obstacle Add NavMesh Obstacle Component Now Choose Desired Shape For Obstacle , I would Suggest To use Box , Now Adjust The Size So That the It Covers Your Obstacle Object , For Now To Test Just Use Value Of 2 In all X,Y,Z And Enable The Carve Option . Now In The Scene You Can Try To Move Your Obstacle And You Will See The NavMesh Around The Obstacle Gets Modified . Now Play the Scene And Give Target to Your Player And in Scene View bring The Obstacle In front Of Player . now It Will Not Go Through The Obstacle but Will Find New Path . Again For Fun You can Move Obstacle In front Of Player And Player Will Find New Way to Reach The Target . have Fun