Support Forum

UpdateGraphsNoBlock - Tower Defense

Hey I’m trying to use UpdateGraphsNoBlock for my Tower Defense game to avoid the path being blocked by a Tower.

        previewTower.position = transform.position;

        var guo = new GraphUpdateObject(previewTower.GetComponent<BoxCollider>().bounds);
        var spawnPointNode = AstarPath.active.GetNearest(spawnPosition).node;
        var goalNode = AstarPath.active.GetNearest(goalPosition).node;

        //if (PathUtilities.IsPathPossible(spawnPointNode, goalNode))
        if (GraphUpdateUtilities.UpdateGraphsNoBlock(guo, spawnPointNode, goalNode, true))
        {
            Debug.Log("Can place a Tower here.");
        }
        else
        {
            Debug.Log("Nope, you can't place a tower here.");
        }

At the moment I can move a tower preview arround on tiles with a simple left click. But if I try to block the path completely it jumps into the Debug.Log(“Can place a Tower here.”); but if I move the tower away from the blocked position, it jumps into the else.

Is there any way to fix that or perhaps is there even a better way to update the Graph via mouseclick without blocking the path anyhow in mid game?

I’ve already tried alot playing arround with it and even went through the Forum & Documentation, but didn’t manage to get it fixed, hope you can help me out.

Hi

You can try calling Physics.SyncTransforms before the UpdateGraphsNoBlock function. That’s a possible issue.