A* Pathfinding Project

Point Graph Runtime Updates


#1

I have just bought the pro version. So I could update point graphs at runtime. However I am actually having bit of trouble with it still. I am add nodes via script to the scene, which seems to be working just fine. Then I am trying to Update the local location of the newly added nodes using the GraphUpdateObject, but when I do this the nodes dont actually get updated connections are not applied. I also get this error (Debug.LogError(“Error while updating graphs\n”+e)not really sure why I feel as though I have followed the documentation correctly.

here is a bit of my code.

THIS CODE IS ON THE NODE ITSELF WHEN IT CREATED

public AstarPath aStarPath;

// Use this for initialization
void Start () {
	aStarPath = GameObject.FindObjectOfType<AstarPath> ();


	aStarPath.AddWorkItem (new AstarWorkItem (ctx => {
		
		var graph = aStarPath.data.pointGraph;
		Debug.Log(graph.name);
		var node = graph.AddNode ((Int3)transform.position);


		ctx.QueueFloodFill();
		

							
		Debug.Log (graph.CountNodes ());
		}));
	
}

THIS CODE IS WHAT SPAWN THE NODE AND UPDATES GRAPH

void Update () {

	ray = Camera.main.ScreenPointToRay (Input.mousePosition);

	if(Physics.Raycast(ray, out hit))
	{
		if(Input.GetButtonDown("Fire1"))
		{
			GameObject obj = Instantiate (node, new Vector3(hit.point.x, hit.point.y +1,hit.point.z), Quaternion.identity) as GameObject;

			GraphUpdateObject myGUO = new GraphUpdateObject ();
			Vector3 v = hit.point;
			Vector3 boundPoint = v;
			myGUO.bounds = new Bounds (boundPoint, new Vector3 (10.5f, 10.5f, 10.5f));
			myGUO.updatePhysics = true;

		
			aStarPath.UpdateGraphs (myGUO,0.25f);


		}
	}
	
}

#2

Do you think you could post what the actual error is? That is just the code that logs the error, but not the error itself.


#3

Error while updating graphs
System.NullReferenceException: Object reference not set to an instance of an object
at Pathfinding.PointNode.ContainsConnection (Pathfinding.GraphNode node) [0x0002a] in C:\Users\Daniel\Desktop\Colony\Colony\Assets\AstarPathfindingProject\Generators\NodeClasses\PointNode.cs:58
at Pathfinding.PointGraph.Pathfinding.IUpdatableGraph.UpdateArea (Pathfinding.GraphUpdateObject guo) [0x00107] in C:\Users\Daniel\Desktop\Colony\Colony\Assets\AstarPathfindingProject\Generators\PointGenerator.cs:494
at Pathfinding.GraphUpdateProcessor.ProcessRegularUpdates (Boolean force) [0x0012a] in C:\Users\Daniel\Desktop\Colony\Colony\Assets\AstarPathfindingProject\Core\Misc\GraphUpdateProcessor.cs:254
UnityEngine.Debug:LogError(Object)
Pathfinding.GraphUpdateProcessor:ProcessRegularUpdates(Boolean) (at Assets/AstarPathfindingProject/Core/Misc/GraphUpdateProcessor.cs:256)
Pathfinding.GraphUpdateProcessor:ProcessGraphUpdates(Boolean) (at Assets/AstarPathfindingProject/Core/Misc/GraphUpdateProcessor.cs:186)
Pathfinding.WorkItemProcessor:ProcessWorkItems(Boolean) (at Assets/AstarPathfindingProject/Core/Misc/WorkItemProcessor.cs:241)
AstarPath:PerformBlockingActions(Boolean) (at Assets/AstarPathfindingProject/Core/AstarPath.cs:800)
AstarPath:Update() (at Assets/AstarPathfindingProject/Core/AstarPath.cs:784)


#4

Ah. That is indeed a bug.
I will include the fix in the next update. In the meantime you can add this line

if (connections == null) return false;

to the start of the PointNode.ContainsConnection method.