Documentation

Unity Engine


User Manual

Script Reference

Unity Engine


GetGeneratedLinkNodes(NavMeshDataInstance, NativeSlice<NavNode>, int, int)

Retrieves the NavNode identifiers for internal navigation links baked into the specified NavMeshDataInstance.
Read time 2 minutesLast updated 22 days ago

Definition

public readonly int GetGeneratedLinkNodes(NavMeshDataInstance navMeshInstance, NativeSlice<NavNode> linkNodes, int start = 0, int length = 2147483647)

Parameters

navMeshInstance

The NavMeshDataInstance that contains the baked links.

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

Type

Description

intThe number of NavNode identifiers written into
linkNodes
.

Remarks

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.

Examples

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