Home

Awesome

Custom Nav Mesh

Alternative to Unity's NavMesh system where the agents avoid the other non-moving agents in their pathing. It uses the official navigation system, but you have to use its components instead. Compatible with NavMeshComponents.

How it works

How do the agents avoid others? Unity's NavMeshAgent only goes around NavMeshObstacles and ignores the other agents in their path. By disabling NavMeshAgent and enabling NavMeshObstacle when an agent is not moving noticeably, the agents now avoid other non-moving agents in their pathing.

Unity's NavMeshAgentCustomNavMeshAgent

1. Setting the destination to the blue target's exact center position.

What if a moving agent collides against a stopped agent that's currently in obstacle mode? By default, it wouldn't be able to push it. However, by:

2. The duplicated NavMesh components. The hidden components are on the right side.

You can have agents push the other agents. For the CustomNavMesh system to work, you must use its custom components, which are identical to the original ones, making the transition seamless.

NavMeshAgent vs NavMeshObstacle "Agents"CustomNavMeshAgents

3. Overlapping agents by throwing one against the others. The agents are green and the obstacles blue.

Why not just switch the agents back to NavMeshAgent instead? That wouldn't work because switching from NavMeshObstacle to NavMeshAgent isn't instant — it would take at least two frames.

What are the disadvantages? Every NavMesh component is duplicated, which makes it less performant. However, it shouldn't be noticeable in most situations.

Custom classes

CustomNavMesh – you can choose the hidden game objects relative position and whether or not they are rendered by accessing the class or through its singleton present in the scene.

4. Changing CustomNavMesh fields.

How To Get Started

Clone or download this repository and open the project in Unity. Alternatively, you can copy the contents of Assets/CustomNavMesh to an existing project.

The scenes used for the GIFs are available in the Assets/Examples folder. Just hit the Space Bar in play mode to test it.

Note: This project is using the Unity 2022.3 LTS version. Tested in PC Standalone, Android, and WebGL.

Final thoughts

Things that I might implement later:

If you need help adding this to your project or have any questions, just message me and I'll try to help. I'm also interested in any tips or suggestions you may have, cheers!