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;
}