How to ask if a point is walkable or not

I need to create an if statement to ask the compiler if the Vector3 rallypoint is on the recast graph scan or not. Does anyone know the syntax I would use to ask that question in code?

Hi

For a recast graph, you can do this:

if (AstarPath.active.data.recastGraph.PointOnNavmesh(point, NNConstraint.Walkable)) {
    Debug.Log("Point is on the navmesh");
}

Thank you

The compiler says ‘NNConstraint’ does not contain a definition for ‘Walkable’
what do I do about that?

That was fixed by a lowercase walkable. But the new error is “an object reference is required for non-static field, method, or property ‘NNConstraint.walkable’.” What do I do about that?

I guess you are not using V5 of the package?
If not, you can use .Default instead.

I can upgrade I was putting that off for a long time.

Actually I am using version 5.0. I can update to 5.1.1 if you think it would help.

I tried using NNConstraint.Default. The error code I got says "cannot implicitly convert type ‘Pathfinding.GraphNode’ to ‘bool’

Sorry, I missed that in my code snippet. You’ll need to do a comparison for != null.

if (AstarPath.active.data.recastGraph.PointOnNavmesh(point, NNConstraint.Walkable != null))
{
Debug.Log(“Point is on the navmesh”);
}
?

How do I set up the comparison?

its still giving me “object reference it required for non-static fields”

From your code it’s unclear which reference is null. If you add some debug logging before the conditional statement you can test for whether or not the various references you’re calling are null, such as AstarPath.active.data.recastGraph.

If you want you can also create a static reference to a Walkable constraint, such as:

public static readonly NNConstraint nnConstraintDefault = NNConstraint.Walkable;

This will allow you to call the constraint when querying your graphs from anywhere in your codebase.

if (AstarPath.active.data.recastGraph.PointOnNavmesh(point, NNConstraint.Walkable) != null)
{

Sir, it is still saying “an object reference is required for non-static field, method, or property ‘NNConstraint.walkable’.” How do I set up an object reference?

My code was written by Aron Granberg the creator of A*. I tried plugging in your code and 8 errors popped up. It also somehow stopped the dotted lines that run vertically between {}

That code was written for v5 of the package (note Walkable with capital W). For earlier versions you can do:

if (AstarPath.active.data.recastGraph.PointOnNavmesh(point, NNConstraint.Default) != null)

Btw. This is a large package. I’d recommend checking out a C# tutorial or two before tackling it.

I am using v5, its version 5.0. When I used uppercase Walkable it says ‘NNConstraint’ does not contain a definition for ‘Walkable’. This is a real problem in v5. I can upgrade to v5.1.1 if you think it will help but you have not responded on that.

I have been using C# for a long time. I have implemented 100s of working if statements.

I paid $100 for A* to make my game run smoother and asking if a point is on the graph should be a simple problem for the person who wrote it. Can you please give some code that works?

Hi

This code, that I posted before, will work in v5 and v4:

if (AstarPath.active.data.recastGraph.PointOnNavmesh(point, NNConstraint.Default) != null)

NNConstraint.Walkable (which is identical to .Default, but with a better name) has existed in the API since 5.0.0. Here’s the documentation for it: NNConstraint - A* Pathfinding Project
I’m not sure why that’s not working for you. It should definitely be there in all v5 versions.
Is it Unity saying this, or your IDE? If Unity compiles it correctly, then your IDE may not be correctly configured.

But I’d recommend upgrading anyway, because there have been a lot of fixes between 5.0.0 and the latest version.

OK, it works. Sorry for bothering you so much I should have just tried .Default