Nav3DObstacle
Nav3D allows you to use game objects in the scene as obstacles with a MeshFilter component with a Mesh assigned, or with a Terrain component.
*For obstacles using MeshFilter, make sure the mesh import settings “Read/Write Enabled” flag is set to true.
Attach the Nav3DObstacle component to a game object that you want to be an obstacle in the scene.
You will see the component inspector:
There are following settings:
- Selecting an obstacle processing mode (obstacles processing must be performed after Nav3D is initialized, so that obstacles are taken into account when pathfinding performs to agents can avoid them while moving):
- Runtime – the obstacle will be processed directly during playmode after Nav3D is initialized. This can be useful if an obstacle is generated during playmode.
- Load from binary – the obstacle will be loaded from a pre-baked binary file. In most cases, the configuration of a game scene is known in advance, even before the scene is loaded and Nav3D is initialized. In such cases, it is always preferable to bake the scene obstacles in editor mode and load them from the binary file at the start of the scene. Loading from a binary file is always much faster than processing an obstacle directly at runtime.
- Process children – if enabled, then information about the MeshFilter and Terrain components will be collected for all children of the transform hierarchy. And all children who have these components will be taken into account when processing the obstacle.
*If you want any child element of an obstacle containing a MeshFilter or Terrain not to be taken into account when constructing the navigation graph, then attach the Nav3DObstacleIgnoreTag
component to it.
- Auto-update on change – if enabled, then if the position, rotation or scale of the transform component of an obstacle changes, it will cause it to recalculate the obstacle navigation graph. (The obstacle will first be removed from the obstacle store, then re-processed and added to it.)This function is available for use only for obstacles with the selected Runtime processing mode.
*Since adding an obstacle is always a time-consuming process, updating the obstacle too often can have a negative impact on performance. We recommend using this function for small, isolated obstacles.
- Update min period – how often the obstacle should be updated (in seconds) when the “Update automatically on transform change” option is enabled.
For runtime obstacles, it is possible to remove/re-add them to the storage directly during the playmode. Addition occurs when OnEnable()
is invoked, removal occurs when OnDisable()
is invoked. Accordingly, any runtime obstacle created on the scene during the playmode will be processed and added to the storage. If you delete or disable an obstacle game object, it will be removed from storage. Re-enabling an obstacle will cause it to be re-added to storage.