Skip to main content

NavMesh.CalculatePath(Vector3 sourcePosition, Vector3 targetPosition, NavMeshQueryFilter filter)

Calculate a path between two points and store the resulting path.

Parameters:

NameTypeDescription
sourcePositionVector3The initial position of the path requested.
targetPositionVector3The final position of the path requested.
filterNavMeshQueryFilterA filter specifying the cost of NavMesh areas that can be passed when calculating a path.

Returns:

typeDescription
booleanTrue if a either a complete or partial path is found and false otherwise.
NavMeshPathThe resulting path.

Usage

---@type Vector3
local sourcePosition;

---@type Vector3
local targetPosition;

---@type NavMeshQueryFilter
local filter;


local val0, val1 = NavMesh:CalculatePath(sourcePosition, targetPosition, filter)

Extra Detail

Use this function to avoid gameplay delays by planning a path before it is needed. You can also use this function to check if a target position is reachable before moving the agent. This function is non-asynchronous. It performs path finding immediately which can adversely affect the frame rate when processing very long paths. It is recommended to only perform a few path finds per frame when, for example, evaluating distances to cover points.