Documentation

Unity Engine

Unity Engine

GetAreaIndexForNode(NavNode)

Obtains the area type index assigned to the specified NavMesh node.
Read time 1 minuteLast updated a month ago

Definition

public readonly int GetAreaIndexForNode(NavNode node)

Parameters

The identifier of the NavMesh node to get the area type index for.

Returns

Type

Description

intAn integer from 0 to 31 that identifies the area type of the node.

Remarks

You define area types in the Navigation settings, and an index from 0 to 31 identifies each one. Use the returned value with NavMesh.GetAreaCost to look up the traversal cost for that area.
For more information about defining area types, refer to Areas and Costs.

Examples

using UnityEngine;using UnityEngine.AI;using Unity.AI.Navigation.LowLevel;public class AreaIndexForNodeExample : MonoBehaviour{ void Update() { using NavWorld world = NavWorld.GetDefaultWorld(); NavLocation location = world.MapLocation(transform.position, Vector3.one, 0); if (!world.IsValid(location)) return; int areaIndex = world.GetAreaIndexForNode(location.node); float traversalCost = NavMesh.GetAreaCost(areaIndex); Debug.Log($"Node has area index {areaIndex} with traversal cost {traversalCost}"); }}