Ai Nav update

Hi, is it possible to update the course with the “new” ai navigation ?

The biggest change with the new NavMesh system is that it’s no longer a scene by scene setup, but is instead tied to a component on a GameObject.

Starting with Unity 2022.2, Unity is phasing out the “legacy” NavMesh system in favor of the “new” NavMesh system (which they have been working on since around 2016, and was previously installed via a GitHub link.

Installation

If it isn't installed already, go to the package manager and locate the AI Navigation package and install it.

If you have a current NavMesh, go into the old NavMesh window (it will show as NavMesh (obsolete) and clear the NavMesh. Close that window, as you’ll never be speaking to it again.

Add A NavMeshSurface

Next, you'll either create an Empty GameObject or add to a GameObject a component called a NavMeshSurface. You'll see options for selecting an agent, whether to gather all scene objects or just objects which are children of the GameObject, as well as the Bake and Clear buttons. Press Bake to create the NavMesh, just like you would in the old version. I usually put the NavMeshSurface on the Terrain object so I can always remember where it is.

At this point, you’re technically done. Your NavMeshAgents know how to find the new surface automagically, and everything should work as before. This is, however, just scratching the surface of the power of the new Navigation system.

Multiple Agent Types

In the legacy NavMesh, there has always been an option to select the Agent Type in both the NavMesh and the NavMeshAgent. A default type was there, Humanoid, which you could edit to customize the NavMesh behaviour. You could create other types, but really only one type would work at a time, so it never made much sense to create a new type.

With the new system, you can now create multiple agent types. For example: You might have an agent type for humanoid, which covers just about all the characters from Mixamo, but what about that big Mutant character. He’s bigger, and should have trouble fitting through narrow spaces. Fear not, you can create a new type for that character and define the new navigation characteristics.


You’ll then add a new NavMeshSurface to a GameObject (yep, it can be on the same GameObject you put the others, though it’s harder to see the changes if you want to show only selected in the AINavigation display). You’ll set that new surface’s Agent Type to Mutant and bake. Now there are two NavMeshSurfaces, and the NavMeshAgent will choose the correct one based on the agent type.

In Addition to agent types, you can also set up NavMeshModifiers which you’ll add to GameObjects. You can use this to make certain areas impassable, or to make them have a higher “cost” to travel through. For example, you might put a modifier on the roads (you’ll need actual GameObjects and mesh renderers to represent the roads!) that makes travelling on them preferable to the NavMeshAgent, with a lower area cost. Meanwhile, you might have a swamp that has a higher area cost, making them less preferable to the NavMeshAgent.

2 Likes

Privacy & Terms