Making a mesh of nodes

In my game’s AI I use node-based navigation system, to make random roaming to appear more like search and patrolling.

So what I did is created an actor that’s placed in the middle of every room. It contains an array with links to every other actor that can be reached from this actor, the whole thing forms a graph representation of the level (in theory).
When AI walks into the room, it triggers a box overlap event that sends the AI controller contents of the array, and AI then chooses the next node it’ll go to (It’s a bit more complicated than that, to minimize chances of AI choosing the node it just came from, but that’s irrelevant).

Blue lines represent references that nodes have on each other in their arrays. Basically, it’s a graph.

So the system, so far, is working pretty ■■■■ fine - AI strolls through the map never making weird trajectories, and appears as if purposefully patrolling the area in search for something (the player), never lingering in any room, just like I wanted it to. The problem is that I need to set up the mesh of nodes manually, And I wondered, is there’s a way to make them find each other and fill up their arrays automatically, through pathfinding or something similar?

You could do it with a trace. If any of the actors can ‘see’ each other, then they can trace to each other. For the ones that can’t see, you can put intermediate objects, just for sake of tracing.

The nodes can setup their connections in the construction script as you place them…