Version: Unity 6.5 (6000.5)
LanguageEnglish
  • C#

NavWorld.GetAreaIndexForNode

Suggest a change

Success!

Thank you for helping us improve the quality of Unity Documentation. Although we cannot accept all submissions, we do read each suggested change from our users and will make updates where applicable.

Close

Submission failed

For some reason your suggested change could not be submitted. Please <a>try again</a> in a few minutes. And thank you for taking the time to help us improve the quality of Unity Documentation.

Close

Cancel

Declaration

public int GetAreaIndexForNode(NavNode node);

Parameters

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

Returns

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

Returns 1, the index of the built-in Not Walkable area, when the node isn't valid in this NavWorld.

Description

Obtains the area type index assigned to the specified NavMesh node.

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.

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}");
    }
}