NavNode
Represents a compact identifier for the data of a navigation graph node.
Read time 2 minutesLast updated 8 hours ago
Definition
- Type: Struct
- Namespace: Unity.AI.Navigation.LowLevel
- Assembly: UnityEngine.AIModule
- Implements: IEquatable<NavNode>
public struct NavNode : IEquatable<NavNode>
Remarks
NavWorld operations use it to pinpoint and access nodes in the NavMesh or NavMesh Links. Only one agent type can use each node.
This identifier becomes invalid once the node is removed from the NavMesh, either by completely removing the surface or by modifying the surface in the node's immediate vicinity.
For more information about the surfaces that nodes describe, refer to Walkable Areas.
Additional Resources: NavWorld.IsValid
Examples
using Unity.Collections;using UnityEngine;using Unity.AI.Navigation.LowLevel;public class NavNodeExample : MonoBehaviour{ void Update() { using NavWorld world = NavWorld.GetDefaultWorld(); NavLocation location = world.MapLocation(transform.position, 5f * Vector3.one, -1); if (!world.IsValid(location)) { Debug.DrawRay(transform.position, Vector3.up, Color.red); return; } NavNode node = location.node; Debug.DrawRay(location.position, Vector3.up, Color.green); using NativeArray<Vector3> vertices = new NativeArray<Vector3>(6, Allocator.Temp); using NativeArray<NavNode> neighbors = new NativeArray<NavNode>(10, Allocator.Temp); using NativeArray<byte> edgeIndices = new NativeArray<byte>(neighbors.Length, Allocator.Temp); NavQueryStatus status = world.GetEdgesAndNeighbors(node, vertices, neighbors, edgeIndices, out int _, out int neighborCount); if ((status & NavQueryStatus.Success) == 0) return; int available = Mathf.Min(neighborCount, neighbors.Length); for (int i = 0; i < available; i++) { if (neighbors[i].IsNull()) continue; // A NavNode is only an identifier. CreateLocation obtains a position from it. NavLocation neighborLocation = world.CreateLocation(transform.position, neighbors[i]); if (!world.IsValid(neighborLocation)) continue; Debug.DrawLine(location.position, neighborLocation.position, Color.magenta); } }}
Methods
Method | Description |
|---|---|
| Equals | Checks whether this |
| GetHashCode | Obtains the hash code of this |
| IsNull | Determines whether this |
Operators
Operator | Description |
|---|---|
| operator == | Returns true if two |
| operator != | Returns true if two |