Version: Unity 6.5 (6000.5)
LanguageEnglish
  • C#

NavQueryStatus

enumeration

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

Description

Bit flags representing the resulting state of NavWorld operations.

The main values are Success, Failure and InProgress. A status usually has only one of these main flags set. Unity sets the secondary flags (details) when it encounters specific issues during the operation. Apply StatusDetailMask as a bitmask to retain only the active secondary flags.

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

public class NavQueryStatusDetailMaskExample : MonoBehaviour
{
    public Transform target;
    NavWorld m_World;
    NavQueryBuffer m_Buffer;

    void OnEnable()
    {
        m_World = NavWorld.GetDefaultWorld();
        // Deliberately small so the query is likely to run out of node budget and set a detail flag.
        m_Buffer = new NavQueryBuffer(m_World, Allocator.Persistent, 4);
    }

    void Update()
    {
        NavLocation start = m_World.MapLocation(transform.position, Vector3.one, 0);
        NavLocation end = m_World.MapLocation(target.position, Vector3.one, 0);
        if (!m_World.IsValid(start) || !m_World.IsValid(end))
            return;

        NavQueryStatus status = m_World.BeginFindPath(m_Buffer, start, end);
        if ((status & NavQueryStatus.InProgress) != 0)
            status = m_World.ContinueFindPath(m_Buffer, 10, out int _);

        // Keep only the detail flags (Success, Failure and InProgress bits are cleared).
        NavQueryStatus details = status & NavQueryStatus.StatusDetailMask;

        // Keep only the main status flag by masking off every detail bit.
        NavQueryStatus main = status & ~NavQueryStatus.StatusDetailMask;

        if ((details & NavQueryStatus.MaxNodesToVisitExceeded) != 0)
            Debug.Log("The pathfinding buffer was too small; increase maxNodesToVisit.");

        Debug.Log($"Main flag: {main}, detail flags: {details}");
    }

    void OnDisable()
    {
        m_Buffer.Dispose();
        m_World.Dispose();
    }
}

Properties

Property Description
FailureThe NavWorld operation didn't complete successfully and produced no usable result.
SuccessThe NavWorld operation completed successfully and produced a valid result for the caller to consume.
InProgressThe NavWorld operation has started but hasn't yet finished and requires additional calls to advance.
StatusDetailMaskBitmask that has 0 set for the Success, Failure and InProgress bits and 1 set for all the other flags.
InvalidParameterA parameter didn't contain valid information, useful for carrying out the NavMesh query.
MoreDataAvailableThe output buffer provided to the query was too small to hold all the results.
MaxNodesToVisitExceededQuery ran out of node stack space during a search.
PartialResultQuery didn't reach the end location, returning best guess.