Search Unity

How to use Get Path Status with Visual Scripting ?

Discussion in 'Visual Scripting' started by Vulpeculus, Aug 31, 2022.

  1. Vulpeculus

    Vulpeculus

    Joined:
    Oct 19, 2019
    Posts:
    5
    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 :

    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4. using NavMeshComponents;
    5.  
    6. public class CalculatePathScript : MonoBehaviour
    7. {
    8.     public GameObject Target;
    9.     public UnityEngine.AI.NavMeshAgent NMA;
    10.  
    11.     private UnityEngine.AI.NavMeshPath _path;
    12.  
    13.     // Start is called before the first frame update
    14.     void Start()
    15.     {
    16.     NMA = GetComponent<UnityEngine.AI.NavMeshAgent>();
    17.     _path = new UnityEngine.AI.NavMeshPath();
    18.  
    19.     }
    20.  
    21.     // Update is called once per frame
    22.     void Update()
    23.     {
    24. NMA.CalculatePath(Target.transform.position, _path);
    25.  
    26. Debug.Log(_path.status);
    27.  
    28.  
    29.     }
    30. }
    31.  
    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 ?
     
    Last edited: Aug 31, 2022
  2. Trindenberg

    Trindenberg

    Joined:
    Dec 3, 2017
    Posts:
    396
    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?
     
  3. Vulpeculus

    Vulpeculus

    Joined:
    Oct 19, 2019
    Posts:
    5
    @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.
     
    Last edited: Aug 31, 2022
  4. Vulpeculus

    Vulpeculus

    Joined:
    Oct 19, 2019
    Posts:
    5
    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.
     
    Last edited: Aug 31, 2022
  5. Trindenberg

    Trindenberg

    Joined:
    Dec 3, 2017
    Posts:
    396
    If you have Human Naming in VS settings, I think this changes everything to Get/Set. I preferred Programmer Naming in the settings.