API reference
API reference
Select your platform
No SDKs available
No versions available

SceneNavigation Class

Extends MonoBehaviour
Manages the creation and updating of a navigation mesh (NavMesh) for scene navigation.
This class handles dynamic NavMesh generation based on scene data, including rooms and anchors, and responds to changes in the scene. It can be also configured to use Unity's built-in scene navigation baking options. When using scene data, MRUKAnchor objects can be used either as navigable surfaces or obstacles. It supports both runtime-created agents and pre-configured ones, adapting to changes in the environment.
// Assuming the SceneNavigation component is attached to this GameObject
var sceneNavigation = GetComponent\<SceneNavigation\>();
// Configure some SceneNavigation settings
sceneNavigation.UseSceneData = true; // Use scene data for NavMesh generation
sceneNavigation.CustomAgent = false; // Use pre-configured agents
// Define navigable surfaces, e.g., floor
sceneNavigation.NavigableSurfaces = MRUKAnchor.SceneLabels.FLOOR;
// Find and assign NavMeshAgents in the scene so that they will be automatically assigned to the NavMesh
sceneNavigation.Agents = new List\<NavMeshAgent\>(FindAnyObjectByType\<NavMeshAgent\>());
// Optionally, handle the NavMesh initialization event
sceneNavigation.OnNavMeshInitialized.AddListener(() =\>
{
    Debug.Log("NavMesh has been successfully initialized.");
});
// Build the NavMesh for the current scene
sceneNavigation.BuildSceneNavMesh();

Fields

When the scene data is loaded, this controls what room(s) will be used when baking the NavMesh.
Used for specifying the type of geometry to collect when building a NavMesh.
Default is PhysicsColliders.
Used for specifying the type of objects to include when building a NavMesh.
Default is Children.
The minimum distance to the walls where the navigation mesh can exist.
Default is 0.2f.
How much vertical clearance space must exist.
Default is 0.5f.
The height of discontinuities in the level the agent can climb over (i.e.
steps and stairs). Default is 0.04f.
Maximum slope the agent can walk up.
Default is 5.5f.
The agents that will be assigned to the NavMesh generated with the scene data.
The scene objects that will contribute to the creation of the NavMesh.
These are the surfaces that the agent can walk on.
The scene objects that will carve a hole in the NavMesh.
A bitmask representing the layers to consider when selecting what that will be used for baking.
The agent's used that is going to be used to build the NavMesh.
Determines whether scene data should be used for NavMesh generation.
When enabled, the NavMesh will be generated using the scene data provided by the MRUKAnchor objects.
Determines whether a custom NavMeshAgent configuration should be used.
If true, a new agent will be created when building the NavMesh.
Allows overriding the default voxel size used in NavMesh generation.
Enable this to specify a custom voxel size.
The NavMesh voxel size in world length units.
Should be 4-6 voxels per character diameter.
Allows overriding the default tile size used in NavMesh generation.
Enable this to specify a custom tile size.
Specifies the tile size for the NavMesh if OverrideTileSize is enabled.
Represents the width and height of the square tiles in world units.

Properties

Event triggered when the navigation mesh has been initialized.
Gets a dictionary mapping MRUKAnchor objects to their corresponding GameObjects that represent obstacles in the environment.
Gets a dictionary mapping MRUKAnchor objects to their corresponding GameObjects that represent surfaces in the environment.
Transform ObstacleRoot[Get]

Member Functions

Toggles the use of global mesh for navigation.
Parameters
useGlobalMesh
Whether to use the global mesh to build the NavMesh
agentTypeID
The agent type ID to use for creating the scene nav mesh, if not specified, a new agent will be created.
Creates a navigation mesh for the entire scene.
Creates a navigation mesh for the scene.
This method creates a navigation mesh by collecting geometry from the scene, building the navigation mesh data, and adding it to the NavMesh. Currently, Unity does not allow the creation of custom NavMeshAgents at runtime. It also assigns the created navigation mesh to all NavMeshAgents in the scene.
Parameters
room
Optional parameter for the MRUKRoom to create the NavMesh for. If not provided, obstacles will be created for all rooms.
Creates a new NavMeshBuildSettings object with the specified agent properties.
Parameters
agentRadius
The minimum distance to the walls where the navigation mesh can exist.
agentHeight
How much vertical clearance space must exist.
agentMaxSlope
Maximum slope the agent can walk up.
agentClimb
The height of discontinuities in the level the agent can climb over (i.e. steps and stairs).
Returns
A new NavMeshBuildSettings object with the specified agent properties.
Creates a NavMeshSurface component and sets its properties.
Removes the NavMeshData from the NavMeshSurface component.
Resizes the NavMeshSurface to fit the room bounds.
Parameters
surface
The NavMeshSurface to resize.
room
The room bounds to use. Default is the current room.
Returns
The bounds of the resized NavMeshSurface.
Resizes the NavMeshSurface to fit the room bounds.
Parameters
surface
The NavMeshSurface to resize.
rooms
The rooms bounds to use.
Returns
The bounds of the resized NavMeshSurface.
Creates obstacles for the given MRUKRoom or all rooms if no room is specified.
Parameters
room
Optional parameter for the MRUKRoom to create the obstacles for. If not provided, obstacles will be created for all rooms.
Creates obstacles for the given MRUKRoom or all rooms if no room is specified.
Parameters
rooms
The rooms for which obstacles will be created.
Creates a NavMeshObstacle for the given MRUKAnchor.
Parameters
anchor
The MRUKAnchor to create the obstacle for.
shouldCarve
Optional parameter that determines whether the obstacle should carve the NavMesh. Default is true.
carveOnlyStationary
Optional parameter that determines whether the obstacle should only carve the NavMesh when stationary. Default is true.
carvingTimeToStationary
Optional parameter that sets the time in seconds an obstacle must be stationary before it starts carving the NavMesh. Default is 0.2f.
carvingMoveThreshold
Optional parameter that sets the minimum world space distance the obstacle must move before it is considered moving. Default is 0.2f.
Creating surfaces will not automatically build a new NavMesh. When changing surfaces at run time, always use BuildSceneNavMesh method
Parameters
room
Optional parameter for the MRUKRoom to create the navigable surfaces for. If not provided, navigable surfaces will be created for all rooms.
Clears all obstacles from the Obstacles dictionary associated with the given MRUKRoom.
If no room is specified, all obstacles are cleared.
Parameters
room
Optional parameter for the MRUKRoom to clear the obstacles for. If not provided, all obstacles will be cleared.
Clears the obstacle associated with the given MRUKAnchor from the Obstacles dictionary.
Parameters
anchor
The MRUKAnchor whose associated obstacle should be cleared.
Clears the surface associated with the given MRUKAnchor from the Obstacles dictionary.
Parameters
anchor
The MRUKAnchor whose associated obstacle should be cleared.

Static Member Functions

Gets the first layer included in the given LayerMask.
Parameters
layerMask
The LayerMask to get the first layer from.
Returns
Returns the first layer included in the LayerMask.
Validates the provided NavMeshBuildSettings against the provided NavMeshBounds.
Parameters
navMeshBuildSettings
The NavMeshBuildSettings to validate.
navMeshBounds
The Bounds to validate the NavMeshBuildSettings against.
Returns
Returns true if the NavMeshBuildSettings are valid, false otherwise.
Did you find this page helpful?
Thumbs up icon
Thumbs down icon