Controlling the lifetime of the NavMesh instance
Occasionally, we need to create navigation on the go because the topology is unknown. This is crucial when dealing with procedural-generated levels. One of the options is to bake the NavMesh at runtime, as we learned before. However, it could be a problem if level topology is really big or complex. Luckily, the NavMesh
components developed by Unity can help us with this task, taking a different approach.
In this recipe, we will learn how to create a NavMesh around an agent without a NavMesh volume, making use of the NavMesh components.
Getting started
It is important to have the NavMeshComponents
directory in our project, as shown in the previous recipe, Setting up our project.
How to do it...
- Create the game level with proper colliders on the floor and/or the terrain where the agent will navigate.
- Create the agent object with the following components set up:
Capsule
orBox Collider
,Rigidbody
, andNavMesh Agent
.
- Create the
NMRealTimeBuilder
class...