Checking for viable path without using startpath

I found your searching for paths page, though I am not having luck achieving my goal. I am using grid graphs in a 2d cell based game (roguelike turn-based). I want to construct a path and then check if the given cell is reachable. Here is the code I have so far:

    private void OnEnable()
    seeker = GetComponent<Seeker>();
    seeker.pathCallback += OnPathComplete;

private void OnDisable()
    seeker.pathCallback -= OnPathComplete;

// Update is called once per frame
void Update()
    if (Input.GetKeyUp("="))
        Path path = ABPath.Construct(player.transform.position,GridInterpreter.grid.CellWorldPosition(30,8), null);
        path.nnConstraint = NNConstraint.None;

private void OnPathComplete(Path p)
    if (p.error) { Debug.Log("Path failed "); }
    else { Debug.Log("Path success"); }

Without the nnConstrain.None bit the player will always move to the closest reachable node once the path is submitted to seeker.StartPath. Once I set it and check whether the cell is reachable (path.error) it always says false (no error, even though it is clearly off limits). Though once I submit the path to seeker.StartPath I can correctly identify the invalid path using the callback method. I need to be able to determine if the path is viable before this because I don’t necessarily want to move the character if the path is successful (for example I may want to move them to the first or second node on the calculated path if successful or wait until a later time to move).



You probably want to have a look at the PathUtilities.IsPathPossible method:

1 Like