I’m using navmeshplus, which is a fork of AI.navigation to allow agents to correctly navigate through tilemaps.
I can get path.status to work with actual code, but not with VS, it always returns ‘pathcomplete’ even when it’s partial.
My code is as such :
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using NavMeshComponents;
public class CalculatePathScript : MonoBehaviour
{
public GameObject Target;
public UnityEngine.AI.NavMeshAgent NMA;
private UnityEngine.AI.NavMeshPath _path;
// Start is called before the first frame update
void Start()
{
NMA = GetComponent<UnityEngine.AI.NavMeshAgent>();
_path = new UnityEngine.AI.NavMeshPath();
}
// Update is called once per frame
void Update()
{
NMA.CalculatePath(Target.transform.position, _path);
Debug.Log(_path.status);
}
}
This code returns a partial path, as it should.
The graph is :
Path.status always returns pathcomplete, no matter what. In my exemple it should return pathpartial, not complete (the destination is on the navmesh, but inaccessible because isolated).
What am I doing wrong ?
The scene and the reffered objects are the same in both cases (target is the targeted object and NMA is the nav mesh agent (or the object containing the agent in the case of VS)), I’m just enabling or disabling the script/graph.
Can someone show me an exemple of how to effectively use path.status with VS ?
In the code, _path is separate, maybe try storing it in a variable as type UnityEngine.AI.NavMeshPath, then CalculatePath. Then from the variable, NavMeshPath.status. Otherwise CalculatePath would not need a path, since it already has the NavMeshAgent?
@Trindenberg
Thanks for your help !
Yes in my first test, _path was a gameobject variable (I cannot find how to format the variable as a navmeshpath like with actual code cf. screen below), and I used this variable as an input for the calculatepath node but it wasn’t working, so I removed it and used getpath from the agent to input the path into the calculatepath node, which, I assume, should be correct ?
I’m pretty sure the error is here but I can’t see how to do it differently, as calculatepath needs a path entry and I see no other way to input a path into it than getpath from the agent.
What I don’t get is that with code, you can find the status on a path (like in my exemple), but with VS, you can’t, it only accepts agents.
Now I see where my problem comes from, but I don’t know how to fix it (could it be a bug in VS?).
According to documentation, status is a property for pathes. cf. https://docs.unity3d.com/ScriptReference/AI.NavMeshPath.html
In VS, get navmeshpath status requires an agent :
The graph above is very simple and effectively brings the Agent (NMA) to its target with set destination (meaning that the path is working correctly), but getting its status always returns pathcomplete unlike with code.
I’m wondering if get path status is the right node to use (I can’t find anything else) ?
EDIT : Got it !!
Get Path Status is not the right node to use in this case.
The right node is Get Status as below :
If someone in the future has the same issue, you have to add nav mesh path in your type options in project settings. Adding AI.navigation (or navmeshcomponents if you’re using navmeshplus) into the library is not enough. You will also have to re-generate custom inspector properties to add the navmeshpath type for variables. Then in the graph just create an new navmeshpath with the new unklocked node and use it for calculatepath and navmeshpath.getstatus.
If you have Human Naming in VS settings, I think this changes everything to Get/Set. I preferred Programmer Naming in the settings.