I need an actor to find the nearest navigable actor to it from an array, move to it, and then move to the next nearest actor.

I’ve got a procedurally generated dungeon. Each room has a few waypoints inside it. I want an actor to find the nearest navigable waypoint actor, and then patrol each room and each waypoint. It’s proven to be a lot more difficult than I imagined.

After the dungeon is finished generating and the waypoints are placed, all the waypoints are put in an array. I thought it would be simple from here on out, but the actor just seems to run to directly to a random waypoint on the map rather than the closest waypoint to the actor.

By using that get(0), you are making an array of only the first waypoint in the array. Just connect all the waypoints to the Find Nearest Actor.

Thank you for the reply.

How would I then be able to remove the waypoint from the array once it’s no longer necessary? I used a copy because otherwise I receive a message that it needs to be wrapped in a struct first.

i would approach it differently.
i would grab all the waypoints, then make an ordered list of them, sorted by … order in which they need to be patroled *1.
I’ll do that at the start, or whenever the patroling needs to start or reset. not everytime it needs a new waypoint.

now for traveling between waypoints i’ll do this:
then have an index variable and just loop normally, incrementing that index and getting the waypoint, until finished.
this will also allow you to travel back & forth.

you’ll need to take into account other events where you’ll need to either stop, or recalculate.

*1 notice i don’t say sorted by distance. since that could lead to errors. you’ll probably need to build some sort of pathfinding algorithm to calculate the traveled distance between waypoints.
Depending on how many waypoints you have you can use a very simple algorithm.

pd your code has an issue.
you should do :
FindNearestActor(ControlledPawn->GetActorLocation(), BubblerWaypointsSelf)
(that is using BubblerWaypointsSelf directly as “Actors to check” input to the node)

instead you are creating an array with only ONE element which is always the 0
then on the Remove node, use the output of find nearest actor instead of the Get node.

1 Like