I’m wondering to know if there is some way to get TRUE or FALSE, if the NavigationMeshAgent will never reach the destination point.
(I want to know it from the beggining, not when the object velocity is 0,0,0)
(c# if is possible)
Thanks a lot if someone knows.
I believe CalculatePath Unity - Scripting API: AI.NavMeshAgent.CalculatePath retuns bool which represent if the path can be calculated - exists. You can’t be sure about dynamic obstacles though.
As mentioned by YoungDeveloper, CalculatePath will give you a result immediately after calling it with the information you’re after. Here’s some sample code from the documentation:
using UnityEngine;
using System.Collections;
public class ExampleClass : MonoBehaviour {
public Transform target;
private NavMeshAgent agent;
void Start() {
agent = GetComponent<NavMeshAgent>();
NavMeshPath path = new NavMeshPath();
agent.CalculatePath(target.position, path);
if (path.status == NavMeshPathStatus.PathPartial) {
}
}
}
However if you’re using SetDestination, you may have to wait a few frames for an answer and the method will be similar. Like before, you check the path status only with the exception that you have to wait for pathPending to be false (otherwise Unity may still be calculating it).
See here for more details: Taming the Pathfinding System
This works fine:
if (this.transform.GetComponent<NavMeshAgent> ().pathPending) {
Debug.Log ("False");
} else {
Debug.Log ("True");
}