Hello,
is there a way to check, if some path is blocked in real time? For example in tower defense. Player wants to build the tower on any place. As he moves the build gizmo, some indicator should show, if this building blocks the path. Updating graph and finding a route every couple of frames seems too slow to me. Is there any faster way to achieve this?
I have managed to test it. Running this method on update makes the game unplayable even on very fast CPU with bigger graph (<10 FPS) So there is a need to tweak it and run only when necessary. However it could be the solution to my problem. Thank you very much for cooperation. And for plugin
Great!
You could also try to disable costly features which you might not need. For example erosion (which is relatively expensive) and “Height Testing” (if your game only on a flat level you might not need it).
Hi
Oops, some old code I hadn’t updated. Sorry about that.
If you find the position where that exception was called, it will be in a method called RevertFromBackup. Replace the contents of that function with:
`
public virtual void RevertFromBackup () {
if (trackChangedNodes) {
if (changedNodes == null) return;
for (int i=0;i<changedNodes.Count;i++) {
changedNodes[i].Penalty = (uint)(backupData[i]>>32);
changedNodes[i].Flags = (uint)(backupData[i] & 0xFFFFFFFF);
changedNodes[i].position = backupPositionData[i];
ListPool<GraphNode>.Release (changedNodes);
ListPool<ulong>.Release(backupData);
ListPool<Int3>.Release(backupPositionData);
}
} else {
throw new System.InvalidOperationException ("Changed nodes have not been tracked, cannot revert from backup");
}
}`
Basically it was just to uncomment, remove the exception and move one line up a bit.
Thanks! But is this fast enough to run it repeatedly every couple of frames? Doesnt it load system too much? Especially smart phones and tablets?
It is relatively slow, but unfortunately it is what you need to do to get that information. Try it and see if it works. It would definitely work on desktop.
Thank you. I will give it a try and then report back the result.
When I try to use this finction, I get an error:
NotSupportedException: Positions not supported yet
Is there somethong I miss? This is my source code:
GraphNode startNode = AstarPath.active.GetNearest(spawnPoint.transform.position, NNConstraint.Default).node; GraphNode endNode = AstarPath.active.GetNearest(myBase.transform.position, NNConstraint.Default).node; Debug.Log("blocks path " + GraphUpdateUtilities.UpdateGraphsNoBlock(new GraphUpdateObject(GameObject.Find("rock1").collider.bounds), startNode, endNode, false));
Hi
Yep, that is possible.
See http://arongranberg.com/astar/docs/class_pathfinding_1_1_graph_update_utilities.php#af1d9912f395e3a1b5ef4f21d1f19da74