Version: Unity 6.5 (6000.5)
LanguageEnglish
  • C#

NavWorld.GetGeneratedLinkNodes

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 GetGeneratedLinkNodes(NavMeshDataInstance navMeshInstance, NativeSlice<NavNode> linkNodes, int start, int length);

Parameters

Parameter Description
navMeshInstance The NavMeshDataInstance that contains the baked links.
linkNodes The buffer to fill with the NavNode identifiers of the baked links. It can have zero capacity when you need only the count returned by NavWorld.GetGeneratedLinksCount.
start The zero-based index of the first baked link to retrieve. The default value is 0.
length The maximum number of baked links to retrieve. The default value is int.MaxValue, which retrieves all the remaining links from start.

Returns

int The number of NavNode identifiers written into linkNodes.

Description

Retrieves the NavNode identifiers for internal navigation links baked into the specified NavMeshDataInstance.

Certain NavMesh baking workflows produce internal navigation links stored directly in the NavMeshData that act similarly to NavMesh Links but aren't individually accessible as separate runtime objects. Use NavWorld.GetGeneratedLinksCount to determine how many such links a NavMeshDataInstance contains before sizing the linkNodes buffer.

The start and length parameters let you retrieve a subset of the full list. Retrieving a subset is useful when you process large batches.

Additional resources: NavWorld.GetGeneratedLinksCount, NavWorld.GetLinkNode, NavWorld.IsValid

using Unity.Collections;
using UnityEngine;
using UnityEngine.AI;
using Unity.AI.Navigation.LowLevel;

public class GeneratedLinkNodesExample : MonoBehaviour
{
    public NavMeshData data;
    NavMeshDataInstance m_Instance;

    void OnEnable()
    {
        // Query the links right after adding the data, so that re-enabling this component
        // re-reads the links of the instance it just created.
        m_Instance = NavMesh.AddNavMeshData(data);

        using NavWorld world = NavWorld.GetDefaultWorld();
        int total = world.GetGeneratedLinksCount(m_Instance);
        NativeArray<NavNode> links = new NativeArray<NavNode>(total, Allocator.Temp);
        int written = world.GetGeneratedLinkNodes(m_Instance, links);
        for (int i = 0; i < written; i++)
            Debug.Log($"Generated link {i}: agent type {world.GetAgentTypeIdForNode(links[i])}");
        links.Dispose();
    }

    void OnDisable()
    {
        m_Instance.Remove();
    }
}