Nav3DObstacle
To manage obstacles on the scene, the Nav3DObstacle component is designed. Attach it to a game object that you want to be an obstacle in the scene.
You will see the component inspector:
It has the 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 many 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 always makes sense to bake scene obstacles in editor mode, and load them from a binary file at the start of the scene. Loading from a binary file is always much faster than processing an obstacle directly in runtime.
- Auto add child transforms – 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.
- Update automatically on transform 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’s 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 re-add it to storage.