UpdateGraphsBoBlock returns false even though its blocked. In certain mazes?

Hello

I just recently bought the pro version of A Star in hope of UpdateGraphsBoBlock to work.
I simply cant get it to work, somethings it work but then sometimes its not working.

Below is the full code for placing my towers. Its runs that function and it actually works mostly, but when i build like show in image, or sell on tower in the top lane. Im able to block path.

The debugger returns true on the UpdateGraphsBoBlock as if the path is not blocked.
But as you can see on the image its CLEARLY blocked.

In the documentation it says:

Note

> This might return true for small areas even if there is no possible path if AstarPath.minAreaSize is greater than zero (0). So when using this, it is recommended to set AstarPath.minAreaSize to 0. (A Inspector -> Settings -> Pathfinding)*
https://arongranberg.com/astar/documentation/3_6_8_eaccccc/class_pathfinding_1_1_graph_update_utilities.php
That is why i bought the Pro version so this would be fixed?

Can i please have some help in this matter?

Max nearest node is 1.


        GameObject _turret = (GameObject)Instantiate(blueprint.prefab, GetBuildPosition(), Quaternion.identity);
        turret = _turret;
        turretBlueprint = blueprint;
        
        GameObject effect = (GameObject)Instantiate(buildManager.buildEffect, GetBuildPosition(), Quaternion.identity);
        Destroy(effect, 5f);

        var guo = new GraphUpdateObject(turret.GetComponent<Collider>().bounds);
        guo.updatePhysics = true;

        Debug.Log(guo);

        GraphNode node1 = AstarPath.active.GetNearest(nodeStart1.position, NNConstraint.Default).node;
        GraphNode node2 = AstarPath.active.GetNearest(nodeEnd2.position, NNConstraint.Default).node;

        Debug.Log(turret.gameObject.GetComponent<BoxCollider>().bounds);
        Debug.Log(turret.gameObject.GetComponent<Collider>().bounds);
        UnityEngine.Physics.SyncTransforms();

  Debug.Log("UpdateGraphsBoBlock: " + GraphUpdateUtilities.UpdateGraphsNoBlock(guo, node1, node2, true));
        if (GraphUpdateUtilities.UpdateGraphsNoBlock(guo, node1, node2, true))
            {
            Debug.Log("BUILDING TOWER");
            aSource.PlayOneShot(buildsound);

            //GameObject _turret = (GameObject)Instantiate(blueprint.prefab, GetBuildPosition(), Quaternion.identity);
            //turret = _turret;

            //turretBlueprint = blueprint;

            PlayerStats.Money -= blueprint.cost;
            //buildManager.DeselectNode();

            var test = turret.ToString();

            string splitTekst1 = test.Split('(')[0].ToString();
            string splitTekstResult = splitTekst1;

            foreach (KeyValuePair<string, GTD_Towers> attachStat in GTD_GameData.TowersData)
            {
                
                if (attachStat.Key.Contains(splitTekstResult))
                {
                    //TowerToUpgradeTo.upgradedPrefab = Resources.Load<GameObject>("Towers/" + attachStat.Key);

                    //// Debug.Log("ATTACHKEY " + attachStat.Key);

                    upgradedTurretBlueprint.prefab = Resources.Load<GameObject>("Towers/" + attachStat.Key);
                    //// Debug.Log("UPGRADE PHASE 1: " + upgradedTurretBlueprint.prefab);

                    upgradedTurretBlueprint.cost = attachStat.Value.Cost;
                    var UpgradeTowerTest = attachStat.Value.UpgradeTower.ToString();
                    //// Debug.Log("NEXT UPGRADED TOWER IS: " + UpgradeTowerTest);

                    if (UpgradeTowerTest == "Max")
                    {
                        //// Debug.Log("Turret Max!");
                        buildManager.DeselectNode();
                        isUpgraded = true;
                        return;
                    }
                    upgradedTurretBlueprint.upgradedPrefab = Resources.Load<GameObject>("Towers/" + attachStat.Value.UpgradeTower);
                    //// Debug.Log("UPGRADE PHASE 2: " + upgradedTurretBlueprint.upgradedPrefab);

                    upgradedTurretBlueprint.upgradeCost = attachStat.Value.Cost * 2;

                }
            }

            AstarPath.active.UpdateGraphs(guo);
            TowerHasBeenBuildOnNode = true;
            BuildManager.instance.DeselectNode();
            TOWER_BUILDING = false;
        }
        else
        {
            aSource.PlayOneShot(failbuildsound);
            Debug.Log("NOT ALLOWED TO BLOCK PATH!!");

           // Bounds bounds1 = turret.GetComponent<BoxCollider>().bounds;
           // GraphUpdateObject guo1 = new GraphUpdateObject(bounds1);
            //Destroy(turret.gameObject);
            turret.SetActive(false);
            //AstarPath.active.UpdateGraphs(guo1);
            this.turret = null;

            AstarPath.active.UpdateGraphs(guo);
            BuildManager.instance.DeselectNode();
            
            
            
            //Destroy(turret);
            //////////StartCoroutine(TimerBuildingBlocked());
            Popup.TriedToBlockPath = true;
            TOWER_BUILDING = false;
        }
       // AstarPath.active.Scan();
        
        Debug.Log("FINISHED BUILDING TOWER!");
   public void SellTurret()
    {
        if (TOWER_BUILDING == true)
        {
            return;
        }
       
        TOWER_SELLING = true;

        PlayerStats.Money += turretBlueprint.GetSellAmount();



        GameObject effect = (GameObject)Instantiate(buildManager.sellEffect, GetBuildPosition(), Quaternion.identity);
        Destroy(effect, 5f);

        Bounds bounds = turret.GetComponent<Collider>().bounds;
        GraphUpdateObject guo = new GraphUpdateObject(bounds);
        //Destroy(turret.gameObject);
        turret.SetActive(false);
        AstarPath.active.UpdateGraphs(guo);

        towerWasSold = true;
        turretBlueprint = null;
        this.turret = null;
        TowerHasBeenBuildOnNode = false;

        buildManager.DeselectNode();

        UnityEngine.Physics.SyncTransforms();
        AstarPath.active.Scan();
        TOWER_SELLING = false;
}

Bump. I still have this issue been ongoing issue for 3 months now.

Not a single one have made field mazes? Have everyone just build mazes that is predefined?

Hi

You are linking to a piece of documentation that is several years old. Which version of the package are you using?

If you use a normal UpdateGraphs call instead of UpdateGraphsNoBlock, does it update the graph correctly? (you can verify by setting the A* Inspector -> Settings -> Graph Coloring to ‘Areas’, disconnected regions should have different colors).

1 Like

Hi Aron

Im using version 4.2.15 pro version.
I tried for 2 days now debugging, i i get 2 different areas after the tower have been placed.
Its like the UpdateGraphsNoBlock is not updating before after the function has run.
After it has run i get logs that i cant build in that zone, and that is the UpdateGraphsNoBlock function?

Hi

Since you reported one of your own threads it sounds like you managed to solve this?

I’m curious about the solution to this as I am currently trying to accomplish the same thing and I also came across that same piece of documentation.

I’m attempting to run 2 functions, first I use the collider bounds to check that all blocks within the bounds are walkable, then I verify that there would be no blockages and do an action. But it seems I can still block the path with this code below…

        public bool CheckForBlocks(Collider collider, Vector3 start, Vector3 destination)
        {
            var guo = new GraphUpdateObject(collider.bounds);
            var startPointNode = AstarPath.active.GetNearest(start).node;
            var goalNode = AstarPath.active.GetNearest(destination).node;
            return GraphUpdateUtilities.UpdateGraphsNoBlock(guo, startPointNode, goalNode);
        }

        public bool AllNodesAreWalkable(Collider collider)
        {
            var nodes = AstarPath.active.data.gridGraph.GetNodesInRegion(collider.bounds);
            foreach (GraphNode node in nodes)
            {
                if (!node.Walkable)
                    return false;
            }
            return true;
        }

and I’m calling these functions like this

            if (!_validator.AllNodesAreWalkable(_collider))
                return $"Not All Nodes are walkable!";

            if (!_validator.CheckForBlocks(_collider, start, end))
                return $"Placement Canceled. Path cannot be blocked!";

EDIT: Never mind, I apparently am just a dingus; I was passing the incorrect starting & ending positions to grab nodes from. I tried it with hard coded numbers and it worked as expected.
I will leave this post here though for future devs :wink:

1 Like