 Brad
|
Hi, I’m using this to build a Tower Defence game. So far I’m able to update the graph when I place towers (see code below) but the Seeker agent doesn’t re-calc its path (and hence runs into the new towers).
Each tower prefab has the following C# code attached; this works and updates the graph with new red blocks seen in the editor (although if I include either of the commented-out settings for the GUO the update doesn’t work).
void Start ()
{
Collider col;
col = collider;
Bounds newBounds = col.bounds;
GraphUpdateObject guo = new GraphUpdateObject (newBounds);
//guo.updatePhysics = true;
//guo.modifyWalkability = true;
guo.setWalkability = true;
AstarPath.active.UpdateGraphs (guo);
}
Is there an extra line of code I need to add here or on the seekers to make sure they update their paths after a graph update?
Thanks in advance!
|
 Hasan Bozok
|
You build the tower over a walkable path i think, i am not sure but i think you should use the collider of path which is under your tower.What i want to say is, if you are placing towers over a slot which has an collider for path calculation, you should use that slots collider’s bounds.
|
 Aron Granberg
|
There is a callback named OnGraphsUpdated which you can register to. Then you can have a function be called every time the graphs are updated (to for example recalculate the paths).
public void OnEnable () {
//Register to the callback
AstarPath.OnGraphsUpdated += MyUpdateFunction;
}
public void OnDisable () {
//To prevent it from receiving callbacks when the object has been destroyed
AstarPath.OnGraphsUpdated -= MyUpdateFunction;
}
public void MyUpdateFunction (AstarPath active) {
//Recalculate the path
}
|
 Aron Granberg
|
Okay, that’s weird… It should work if you only set “updatePhysics = true”, though this is practically what you are doing since that’s the default value.
If you are using version 3.0.6 (I think), you might want to upgrade, that version had a bug related to graph updates.
|