[SOLVED] ConstantPath Outline Help

Hi. I am currently developing a game based on the Xcom mechanics. I bought the Pro version because it allows multiple level grids. I need a way to show the selected player character how far they can run with the current action points. So I need a way to draw an outline around all reachable gridnodes.

I found the following link: A* Pathfinding Project: ConstantPath Class Reference

This function seems to do exactly what I need. I tried to put this in, but I can’t get it to work. I don’t know how to get the list. Can someone give me an example of this? The seeker does not return anything.

Additionally: How do I use the allNodes list to make a drawing from it?

I would be very grateful for your help.

Hi, I possibly found a solution here

, but I cant verify it. The SampleScene doesnt work with the functions I want to test *Constant Path and FloodPath@. See Video. I’m using the current Beta by the Way.

Hi

You can do something like:

// Here you create a new path and set how far it should search. Null is for the callback, but the seeker will handle that
ConstantPath cpath = ConstantPath.Construct(transform.position, 2000, null);
// Request the seeker to search for the path
seeker.StartPath(cpath, null);
cpath.BlockUntilCalculated();

for (int i = 0; i < cpath.allNodes.Count; i++) {
    Debug.DrawRay((Vector3)cpath.allNodes[i].position, Vector3.up, Color.red, 2);
}

Btw, here’s the up to date documentation: ConstantPath - A* Pathfinding Project

See also Searching for paths - A* Pathfinding Project

1 Like

Thank you for your fast reply.

When I do this, I get the exception:

Exception: This function only handles ABPaths, do not use special path types
Pathfinding.AIPath.OnPathComplete (Pathfinding.Path newPath) (at Library/PackageCache/com.arongranberg.astar@4.3.61/Core/AI/AIPath.cs:296)
Pathfinding.Seeker.OnPathComplete (Pathfinding.Path p, System.Boolean runModifiers, System.Boolean sendCallbacks) (at Library/PackageCache/com.arongranberg.astar@4.3.61/Core/AI/Seeker.cs:328)
Pathfinding.Seeker.OnPathComplete (Pathfinding.Path path) (at Library/PackageCache/com.arongranberg.astar@4.3.61/Core/AI/Seeker.cs:295)
Pathfinding.Path.ReturnPath () (at Library/PackageCache/com.arongranberg.astar@4.3.61/Core/Path.cs:901)
Pathfinding.Path.Pathfinding.IPathInternals.ReturnPath () (at Library/PackageCache/com.arongranberg.astar@4.3.61/Core/Path.cs:959)
Pathfinding.PathReturnQueue.ReturnPaths (System.Boolean timeSlice) (at Library/PackageCache/com.arongranberg.astar@4.3.61/Core/Misc/PathReturnQueue.cs:56)
UnityEngine.Debug:LogException(Exception)
Pathfinding.PathReturnQueue:ReturnPaths(Boolean) (at Library/PackageCache/com.arongranberg.astar@4.3.61/Core/Misc/PathReturnQueue.cs:58)
AstarPath:BlockUntilCalculated(Path) (at Library/PackageCache/com.arongranberg.astar@4.3.61/Core/AstarPath.cs:1974)
Pathfinding.Path:BlockUntilCalculated() (at Library/PackageCache/com.arongranberg.astar@4.3.61/Core/Path.cs:417)
cPathVisualizer:Start() (at Assets/cPathVisualizer.cs:16)

Ah, yes. That is from the movement script which gets confused about why you’d want to send a ConstantPath to it (makes no sense to follow such a path type). The AIPath script listens to all path requests completed by an attached Seeker.

You can use the AstarPath component directly to avoid this:

// Here you create a new path and set how far it should search. Null is for the callback, but the seeker will handle that
ConstantPath cpath = ConstantPath.Construct(transform.position, 2000, null);
// Request the seeker to search for the path
AstarPath.StartPath(cpath);
cpath.BlockUntilCalculated();

for (int i = 0; i < cpath.allNodes.Count; i++) {
    Debug.DrawRay((Vector3)cpath.allNodes[i].position, Vector3.up, Color.red, 2);
}
1 Like

Thank you so much! This is a huge milestone for me :slight_smile:

I instantiated an object at every position with your code. Works flawlessly. Now I unly need to understand how the score is calculated, but I’m sure, I can find it out pretty easily.

1 Like