Detecting Actor to Spawn From? Dungeon Generation

Hello,
I have been trying to give some refinement to the way I currently generate my level for an artistic choice, and also in order to prevent rooms overlapping at their exits which allows players to get outside of the map.

I have been unsuccessful thus far and so I have come here

This is the system I’ve fallen back on, it allows for me to set the first room then it chooses a random next room or corridor as long as it fits considering several hit boxes. I have on the right in the details two unused arrays which one holds all the rooms, and the other all of the corridors. I last tried using a flip flop off of the false branch which takes the boolean “Corridor?” as it’s input "which by default is true because after the first room I would want a corridor. on the flipflop a I set corridor? to false and then set the selected Room to Spawn to a random corridor. The flipflop b sets corridor? to true and spawns a room. I figured this would give some results, but it only resulted in a less complete generation, but rooms would still spawn after rooms. I presume because I have more than one room exit in most rooms that the flip flop would for a 3 exit room try to spawn a corridor on the first and last and a room on the second. and since they have access to fewer assets they would just continue after they fail.

I want for my system to if the next room is spawning off of a room have a 100% chance to spawn a corridor, and a controllable chance of spawning either a corridor or a room off of a corridor for more interesting layouts.

You need to pass along a parameter per invocation to spawn another actor.
You can either do this with recursion, or with a queue of “things to spawn” that stores a struct of location and type.

Perhaps easiest is to use a dual-function recursion – “SpawnCorridor” and “SpawnRoom.”
Then, Start calling SpawnRoom(location)
SpawnRoom() will walk each of the exits of the room, and call SpawnCorridor(location)
SpawnCorridor() will in turn find a corridor that fits, and walk each of the exits, calling SpawnRoom(location) in turn.

You probably also need an “end cap” geometry that you place when it ends up you put a corridor leading into a blocked space.

Also, in the naive implementation of this algorithm, the “first” spawn (first chosen exit from first room, then first chosen exit from corridor, then first chosen exit from next room …) will generate the majority of your map, which leads to very deep recursion, and a “winding path” through said dungeon. That may be OK for you. If not, you need to formulate your generator as working on a list of locations-and-things-to-spawn and make the function “take the first thing in the list, spawn it, repeat.”

Another approach along those lines is to keep two lists (rooms-plus-exists to spawn, and corridors-plus-exist to spawn.)
Then, have the function pick the first item from the room-to-spawn list, and spawn a room. For each exit in that room, place a work item in the corridors-to-spawn list.
Repeat, until there are no rooms to spawn. Then, take the first corridor-to-spawn, and spawn that. Place each exit in the rooms-to-spawn list, but keep working on corridors until you run out of items in that list.

Repeat, until both lists are empty, or you’re out of space, and seal off all the final stuff with end caps.

I have a handler in another function that makes end caps, and that aside can you elaborate on the dual-function recursion (i’m pretty new to this kind of thing, and when I think of function recursion it means an input and output pin being added to the function) I also am not entirely sure how best to step through each exit

here is an example of both a room and a corridor the connections are child actors


would that just be a for each loop of the child actor type? wouldn’t that cause issues still because multiple rooms/corridors are generating at once it does not limit to one room at a time. would I need to add an identifier to the master class such as my corridor? boolean, but use it to identify if the child being tested was a room or a corridor. and would all of this take place in my room select function or would it have to be handles before the specific call? and yes, I like the winding feel, I plan to expand it with verticality eventually…it has a set number of rooms to spawn integer that limits how many times it will call the spawning function…after it closes any openings with the end caps that keeps it from being infinite