A* Pathfinding Project  3.8.5
The A* Pathfinding Project for Unity 3D
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Properties Events Macros Groups Pages
MovePointNode.cs

Moves and updates a single node in a point graph.If you want to move a single node in a point graph, you might be lost in how to do that in the "correct" way. Would you only update a node's position field, the node would be moved, however all connections would remain even if some might be invalid and no connection costs will have been recalculated to reflect the new position. For that reason this example script is put here. It simply picks a random node (closest node from within a sphere, so not really random) and moves it in a random direction a small distance.

using UnityEngine;
using System.Collections;
using Pathfinding;
public class MovePointNode : MonoBehaviour {
// Update is called once per frame
void Update () {
//Get a random node to update
//GraphNode node = AstarPath.active.GetNearest (Random.insideUnitSphere*20).node;
//Move the node a bit
//node.Position += (Int3)(Random.insideUnitSphere*0.1f);
throw new System.NotSupportedException("Positions not supported");
/*
* //Recalculate the area around the node.
* //No functions for updating a single node is available, so we create
* //a bounds object which contains that node and only a small volume around it
* AstarPath.active.UpdateGraphs (new GraphUpdateObject (new Bounds ((Vector3)node.Position,new Vector3(0.1f,0.1f,0.1f))));
*
* //Make sure the above graph update is done now
* AstarPath.active.FlushGraphUpdates ();
*
* //The update area functions of the built-in graphs generally assumes that the position of the node
* //has not changed, so some connection costs might be wrong
* node.RecalculateConnectionCosts ();
*/
});
//If you want to make sure the update is called directly instead of
//at the end of this frame or after a few frames.
//AstarPath.active.FlushThreadSafeCallbacks ();
}
}