Making a node walkable

Hello,

I have bin trying to make a node walkable on runtime.
I set it to walkable and the node dissapears, but when i set a destination and activate it to move i am getting an error.

“No open points, the start node didn’t open any nodes”

Here is a screenshot of the problem.

This is the code i am using:

`
AstarPath.RegisterSafeUpdate (delegate () {
NNInfo node = AstarPath.active.GetNearest(transform.position);
node.node.walkable = true;
},true);

`

The idea is that it has to set the changed block to walkable.

I also tried but with no effect:

GraphUpdateObject ob = new GraphUpdateObject(transform.collider.bounds); AstarPath.active.UpdateGraphs(ob);

I hope someone can give me a bit more information about this and how to set a specific node to walkable and making it open to paths.

Big thanks in advance!

Regards

I’m finding it difficult to reproduce that error. Could you show me the code you are using to build the path? (The AI script you are using)

Thank you for the fast response!

Here is the code.

i checked the code and is working when they are not on the “changed” blocks.

AI code.

`
using UnityEngine;
using System.Collections;
//Note this line, if it is left out, the script won’t know that the class ‘Path’ exists and it will throw compiler errors
//This line should always be present at the top of scripts which use %Pathfindingusing
using Pathfinding;

public class AstarAI : MonoBehaviour
{
//The point to move to
public Vector3 targetPosition;
private Seeker seeker;
private CharacterController controller;
//The calculated path
public Path path;
//The AI’s speed per second
public int speed = 0;
//The max distance from the AI to a waypoint for it to continue to the next waypoint
public float nextWaypointDistance = 3;
//The waypoint we are currently moving towards
private int currentWaypoint = 0;
public void Start ()
{
speed = 10;
seeker = GetComponent();
controller = GetComponent();
}
public void SetWalk(Vector3 pos, Bounds bou)
{
//NNInfo node = AstarPath.active.GetNearest(pos);
//node.node.Walkable = true;
AstarPath.RegisterSafeUpdate (delegate () {
NNInfo node = AstarPath.active.GetNearest(pos);
node.node.walkable = true;
},true);

	//GraphUpdateObject ob = new GraphUpdateObject(tra.collider.bounds);
	//AstarPath.active.UpdateGraphs(ob);
	//AstarPath.active.UpdateGraphs (bou);
}
public void StartSeeking()
{
	//Start a new path to the targetPosition, return the result to the OnPathComplete function
	seeker.StartPath (transform.position,targetPosition, OnPathComplete);
}
public void OnDisable () 
{    
	seeker.pathCallback -= OnPathComplete;
} 
public void OnPathComplete (Path p) 
{      
	Debug.Log ("Yey, we got a path back. Did it have an error? "+p.error);        
	if (!p.error) 
	{          
		path = p;            
		//Reset the waypoint counter            
		currentWaypoint = 0;        
	}
}     
public void FixedUpdate () 
{        
	if (path == null) 
	{            
		//We have no path to move after yet            
		return;        
	}               
	if (currentWaypoint >= path.vectorPath.Count) 
	{
		GetComponent<DemoWander>().PathMoving = false;
		GetComponent<DemoWander>().PickNewAction();
		Debug.Log ("End Of Path Reached");            
		return;        
	}                
	//Direction to the next waypoint        
	Vector3 dir = (path.vectorPath[currentWaypoint]-transform.position).normalized;        
	dir *= speed * Time.fixedDeltaTime;        
	controller.SimpleMove (dir);               
	//Check if we are close enough to the next waypoint        
	//If we are, proceed to follow the next waypoint        
	if (Vector3.Distance (transform.position,path.vectorPath[currentWaypoint]) < nextWaypointDistance) 
	{            
		currentWaypoint++;            
		return;        
	}    
}

}
`

here are the lines from where i call a function to make them walkable.
1 for the tile he is standing on and 1 for the one in front of him.

`
GetComponent().SetWalk(new Vector3(TileX4,0,TileZ4),new Bounds(new Vector3(TileX4,0,TileZ4),new Vector3(4,2,4)));
GetComponent().SetWalk(transform.position,transform.collider.bounds);

`

Thanks in advance.

First off I just want to point out your OnDisable code is not needed since you send the callback in the StartPath. For that I would do one of 2 things

  1. Remove
    public void OnDisable () { seeker.pathCallback -= OnPathComplete; }
    or

  2. Add/Change
    Add:
    public void OnEnable () { seeker.pathCallback += OnPathComplete; }

And

Change:
seeker.StartPath (transform.position,targetPosition, OnPathComplete); to seeker.StartPath (transform.position,targetPosition);

Second I don’t know the official way to make a node walkable again, but for the time being I am just doing the following
go.layer = 0; AstarPath.active.UpdateGraphs(go.collider.bounds); Destroy(go)

That seems to be the most effective solution I have found so far. It’s simple and doesn’t seem to be much of a performance hit.

If this doesn’t answer your question please elaborate more on your code and desired effect.

Thanks.

Hello,

It did not work.
i will try to explain it better.

I have these blocks as seen in the screenshot, they are a mesh together defided in chunks.
once a block i changed by the AI it turns flat, and at that point the i do not want to rescan but rather change that single block to walkable.

the blocks are not gameobjects and i cannot acces them individually.
There is an array though where i can change them separately but that is through their own class so i cannot acces the transform etc.

in the screenshot above i did not use “UpdateGraphs” and by not using that the nodes dissapear as they should.
However when i do use it this is what happens:
Note: the AI moves blocks by block, it flattens a block then moves to the next etc.

i hope i explained it a bit better this way.

Big thanks in advance.

I see, yes that is much clearer, using walkable is correct but there is much more to it than that. The unwalkable nodes I assume are unwalkable set by scanning? If that is the case then even making a node walkable isn’t enough. Because yes it will be walkable but it will have 0 connections. so you would have to add a connection

node.AddConnection(otherNode, cost)

hmm from what I can find that should do the trick.

If not, then I am sure Aron would be able to give you a much better (and working) answer.
I’m still fairly new to this myself, But figure I’ll attempt to try when I can.

Thanks for the response.

I am trying to get it working, but it throws me an error.

GridNodes do not have support for adding manual connections

public override void AddConnection (GraphNode node, uint cost) { throw new System.NotImplementedException("GridNodes do not have support for adding manual connections"); }

Thanks again for your time.
I will be trying more aswell and if i fix it i will post it here.

Regards

Bump,

I did not manage to get it to work.

I hope someone can help me a bit with this.

Big Thanks!

Hello,

is there any way someone can help me in this matter?

Regards