| Parameter | Description |
|---|---|
| position | The world position of the NavLocation to create. |
| node | The valid identifier of the NavMesh node. |
NavLocation
An object that contains the specified NavMesh node, if valid, and a position located on that node.
When the specified node is invalid, the returned object has an empty and invalid node, and a position equal to Vector3.zero.
Constructs a valid NavLocation from a position and a navigation node.
When the specified node is a polygon, the returned position is the point on the surface of the polygon that is closest to the specified position.
When the specified node is a link, the returned position is the point on the link's end segments that is closest to the specified position. The position lies on the contact line between that segment of the link and a NavMesh surface.
Important: The returned position isn't aligned vertically to the HeightMesh, if one exists.
To obtain reliable positions on the NavMesh, you can also use NavWorld.MapLocation, NavWorld.MoveLocation, and NavWorld.GetPortalPoints.
using UnityEngine; using Unity.AI.Navigation.LowLevel; public class CreateLocationExample : MonoBehaviour { void Update() { using NavWorld world = NavWorld.GetDefaultWorld(); // Map a world position to obtain a valid NavNode for the current polygon. NavLocation mapped = world.MapLocation(transform.position, Vector3.one, 0); if (!world.IsValid(mapped)) return; // Re-create a location at a different point that lies on the same polygon. Vector3 offset = transform.position + new Vector3(0.5f, 0f, 0f); NavLocation custom = world.CreateLocation(offset, mapped.node); Debug.DrawLine(transform.position, custom.position, Color.cyan); } }