Download

Best way to do Procedural Corridor Generation?

Okay, so I’m starting work on a game that has procedural generation as one of the main points of the game and I just have one question on what to use when doing it.

Should I use blueprint actors as hallway pieces and rooms or should I use Static meshes? I’ve also heard of using Instanced levels but I have no Clue on how to use instanced levels. I’ll explain the procedural generation down below, but for now I just want to know which one of these would be good to use when creating a procedural level generator, I’ve seen that using blueprint actors in procedural generation isn’t exactly good on performance, but it seems like using blueprints would allow me to have some control on the actors.

The game is confined to a small level that has different areas each with a different theme and all the procedural generation is, is just hallways that spawn in these areas while also connecting to all of the other areas in the level. Rooms will spawn off from the hallways, each room is going to be prebuilt meaning the room size and what it looks like isn’t procedurally generated. If you need me to explain the procedural generation system more please let me know and I will tell you.

I’ve been trying to toy with procedural generation myself. Unfortunately, there’s not a whole lot about it out there. Here’s one thing I did find:

It’s not a “how to” but you can download the code (all blueprint) from the epic market and dissect it to learn how he did it. I went through the code of that project to figure out a number of things. I didn’t use any of those things, but it gave me ideas about how I could do things.

There is also a free procedural level generator on the epic market

This is mostly C++ but you can again dissect it to see how’s it’s done.

And then there’s the much more complex

The source is available. I haven’t looked into this one myself, but I’m assuming C++

And if you’re willing to spend 20 bucks, someone already did it for you:

IMO some things that need to be defined:

  • Labyrinth or maze-like? (straight with few random rooms or different paths)
  • Will the procedurally generated area be connected to two fixed locations? (entrance & exit)
  • Will it be generated on load or dynamically changed during gameplay?

Thanks for all of these! I knew about the procedural generated project made by epic, but I didn’t know about these other ones. I’ll be sure to take a look

The level spreads out from Different paths from a room spawn point and such or at least I can hope to get something like that.
I want the different areas to be connected via a door and I hope I can make it the door be generated by the level generator instead of a fixed position
The level will be generated when the player loads into the level it won’t do it during gameplay
I can draw up a crappy diagram or something in ms paint if you want to detail the level layout and what the areas look like, but I really just want to know what I can use to make the procedural generation (blueprint actors, instanced levels, static meshes, etc)

Think each path has to be generated by multiple passes of the pathfinding algorithm you decide to use then have them connect to a “hub” or subsequent passes connect along a main path.

You mean have the door placed on different walls or fixed door and randomly rotate the interiors?
:thinking:

It’s ok. I’m not going to do the work :sweat_smile:. What I can do is help with the overall logic. As far as I’m concerned all we need is place blocks on a grid and figure out how to connect them.

Yeah pretty much the system works is just by having sort of like a square divided into 9 sections and each section generates a small group of hallways and then the generator generates hallway connections with a door in the middle dividing the areas at their edges and connecting the areas so you can walk to and from different areas, I guess is the best way to put it?

Not unless you want the entire space filled with hallways and rooms.

IMO:

  1. Generate grid X by X blocks
  2. Generate random obstacles inside the grid
  3. Pathfinder goes from A to B navigating around obstacles. → this would be your main path
  4. Randomly select blocks to spawn rooms from main path → check if the sides are not blocked
  5. Spawn instances of authored assets on each block with correct orientation.

They could just be prebuilt and assembled when populating. After the path has been generated, all you need to do is spawn and move to fill the path, literally like legos.

Your hallways can be made of row of instances, where you could swap one with door on either side or both to place a room.

You will need templates, for example: square rooms 1x1 or 2x2 blocks, large rooms 2x2 or 4x3 blocks, hallways 1x1 2x1 blocks, 1x1 corner hallways, etc, for after the check if there’s available space, place and assemble them along the path.

There’s a plugin in the marketplace called … Dungeon Architect? Something like that.
It has a few algorithms implemented, and, more importantly, an “entity population” mechanism where the algorithms place abstract tags in world space, and the setup places the blueprints or meshes you suggest to populate those locations.
If you like playing with this kind of stuff, it’s pretty fun to play with, although ultimately I’m sure you’ll run into the limitations at the edges of its feature set.

When it comes to the original question: “blueprints” or “static mesh actors?” THERE IS NO DIFFERENCE! Well, there is a small storage difference, and a small instantiation difference, but once your thing is in the level, a static mesh component attached to a custom blueprint that doesn’t move, and a static mesh component attached to a static mesh actor that doesn’t move, will perform the same. And the load/instantiation time difference is minuscule.

Another thing to maybe consider would be to have a builder that uses instanced mesh components – one per “kind” of wall/floor/whatever you need, and then add all the instances to each of the actors. Requires a little bit more setup, could maybe be a bit more efficient – but in these games, it’s almost always fill rate that matters, not per-object overhead, unless you’re building your dungeon of, like, brick-sized pieces.

Blueprints have the nice property that they can randomize themselves a bit when instantiated, and they can also include things like lights and particle effects, too.

Anyway, hope that answers the question, and if you’re interested in evaluating different approaches for procedural generation, you could do worse than buying the dungeon architect plugin and picking it apart.

1 Like

Thank you so much for this! I just wanted to know if blueprint actors were good to use since I figured they’d be very performance heavy if multiple were spawned out and on screen, but I guess it should have been a easy self answer for that. I did buy dungeon architect, it just doesn’t have what I’m looking for unfortunately, its good to have in case I need it, though. I’m gonna go ahead and go with Blueprint actors since it seem much more useful and more customizable generation wise.