TD - Prevent a path from being blocked - ispathpossible / updategraphsnoblock setup help

Hi, I am new to this and am struggling to get ​ispathpossible and updategraphsnoblock to work in my scripts. I have the pro version.

this is my build script -


using UnityEngine;
using Pathfinding;

public class TowerNode : MonoBehaviour
{
    private GameObject tower;

    private void OnMouseDown() {

        if (tower != null) {

            Debug.Log("Can't build here!");
            return;
        }
        
        GameObject towerToBiuld = BuildingManager.instance.GetTowerToBuild();
        tower = (GameObject)Instantiate(towerToBiuld, transform.position, transform.rotation);

        AstarPath.active.Scan();
    }


How do i get either of the two to work when instantiating a tower? are they used like an if statement? e.g


if (isPathPossible = true) {

GameObject towerToBiuld = BuildingManager.instance.GetTowerToBuild();
        tower = (GameObject)Instantiate(towerToBiuld, transform.position, transform.rotation);

        AstarPath.active.Scan();

} else {

Debug.Log ("Cant block the path");

}

a poor example I know.

Thanks for the help

A

Any one got any ideas on this. Appreciate the help

Hi

Sorry for the late reply.
Have you checked out the example code here: https://arongranberg.com/astar/docs/graph-updates.php#blocking? That allows you to do precisely what you want.
You don’t have to scan the whole graph after you are done.

So the part I am now struggling to understand is

var guo = new GraphUpdateObject(tower.GetComponent<Collider>().bounds);
var spawnPointNode = AstarPath.active.GetNearest(spawnPoint.position).node;
var goalNode = AstarPath.active.GetNearest(goalPoint.position).node;

I get an error " The name ‘spawnPoint’ does not exist in the current context " and the same for goalPoint.

what do i need to do to make these reference the spawnpoints and Aitarget i have in?

A

Hi

spawnPoint and goalPoint are variables you are supposed to define. You want to prevent a path from being blocked. These are the starting and end points of the path respectively.