Making an enemy patrol waypoints on a procedurally generated map

I have a procedurally generated dungeon. I want an enemy that patrols the whole level looking for the player. There’s plenty of tutorials of how to make this happen on a regular map, but since it’s procedurally generated I’m not sure what the best way to do that is.

Each room spawns a few invisible waypoint actors. I’ve got a behavior component that on spawn looks for each waypoint actor, puts it into an array, and then the enemy is tasked to move to each waypoint actor, wait a little bit, and then move onto the nearest waypoint actor.

In practice the enemy has about four different waypoints it moves between instead of 50; it doesn’t move from one actor to the nearest, they’re all out of order. For some reason it always runs to the 0,0,0 position even though it isn’t a waypoint.

Can anyone think of a better way to do this? I haven’t had any luck searching online.

Hey there @fartificial! So when it comes to procedural maps, you’re going to need to use runtime navigation meshing to be able to change the navigation mesh on the fly when the map changes. The most likely reason that the agent goes to 0,0,0 is likely because the actor itself isn’t close enough to a point on the navigation mesh to path correctly. This can be because the actor is affecting the NavMesh and the area under it is being taken off of the NavMesh itself, so it’s recommended to use Target actor or pass the location through a Get Random Reachable Point node with a low radius and that should return a more applicable location.

Runtime NavMesh:

Thank you for the reply. I already had the RecastNavMesh set to dynamic. I changed the project settings to Dynamic just incase, but nothing changed, the actor is still running to 0,0,0 occasionally.

Can you print out the movement result enum and also the location the MoveTo is being fed? This will give us an idea of if the location is wrong or the movement is failing and in what way.

One idea that might get you going in the right direction, is on spawn, have the AI actor get all the waypoint actors, test then for distance then sorting them into an array using a for each loop