I need help with Room Generation

Hey! I am trying to make an infinite room generation from premade rooms.

The room includes a room with a collision box inside and spawnpoints. The character has that red sphere which overlaps with spawnpoints to generate rooms.

For now it works for one direction but when I add more off them, it crashes and says that it detected infinite loop. I assume that it means that the spawnpoint is not being deleted before telling to spawn a room and it generates the rooms in one place infinitely.

I tried so many things to fix it, if statements, different ways to check overlapping, timers, but I just can’t find the solution…

Oh and I’m a beginner, I started using Unreal a couple days ago so beginner friendly help would be appreciated :stuck_out_tongue:



When you spawn a new room, the player immediately overlaps the new room, that’s the loop.

You need to disable spawning on a point when a room is connected. Actually take a look, is a room connected, then don’t spawn.

That’s what I tried, I set up a if statement if the spawnpoint overlaps with a room causing it to be deleted and it wasn’t working

I did exactly this with maze segments. When you spawn the room, you can set a reference to the spawned room. If that reference is set, don’t spawn another.

But how? I thought that if a spawnpoint of the other room detects that there is already a room it won’t spawn it and delete itself. How else can I do that?

Like this. Each spawn point consists of the location, and a reference to what’s connected there.

If there’s an overlap, check the reference. If it’s null, connect something and set the reference at the same time. Also, set the reference in the spawned blueprint to this room.

You can set the reference variable to be exposed on spawn, so you can set it as the room is being spawned :slight_smile:

But I delete my Spawnpoints when they Spawn a room so how could they store a reference of that room?

I don’t know exactly what your system / logic is, but with mine, if room A spawned B, then I went back into A, it would unspawn B. So, if I walked in that direction again, maybe C would spawn etc.

Maybe you only spawn once. In which case, it makes sense to remove the spawn points.

If A spawns B, then the spawn points on A and B should be removed ( B as it’s spawning ). ( Only remove the connected spawn points, of course ).

For now my system is supposed to be that my spawnpoints, which are a part of rooms blueprint, spawn the same room with the same amount of spawnpoints so it can go infinitely as I explore. I made a collision box inside the room to check if a new spawned spawnpoints overlap with a room which would mean that there is a room in that place so I call a delete function without spawning a room.

Well, this ( the subject we’re talking about ) is what’s causing the loop.

You just need to find a way that’s right for you to avoid rooms spawning other rooms the moment they are spawned.

Is there a way to store locations of already spawned rooms in Spawn Room Function? So if they match that function will do nothing and delete the spawnpoint?

Don’t try and write one big fat spawn room function. You will go nuts. Also, location is a bit unreliable. Is that good enough for you? What if it’s one unit off?

I’m assuming you have set it up so that each room manages the spawning of the rooms attached to it, and they manage what’s attached to them, etc.

The easiest way is to just keep references with the rooms :slight_smile:

Well, I could try to rewrite it so the room blueprint handles the spawning but I don’t how will it go😅

1 Like

Hi, I don’t know if you’re gonna reply but I reworked my system with a different approach and it works! But there is one problem…Is there a way to generate a chunk of rooms at the start depending on the size of my character’s sphere that overlaps with spawnpoints?

1 Like

I think that might be quite tricky to do based on a collision sphere.

What you could do is, when the character steps into a room, they give that room a ‘token’ ( just an int ).

That room can spawn, and when it does, it subtracts one from the token, and passes it onto the spawned rooms. They do the same.

When the token gets to 0, no more spawning is allowed.

No, I want to spawn more than one room on the start of the game, because the collision sphere doesn’t seem to work when the spawnpoints are spawned in it

That’s what I’m saying. So you insert one room and give it a token of 3, say.

so I will need to create a way to spawn rooms if the the spawning room has a token right?

It’s almost exactly what you have now, except you will have a way of stopping the rooms spawning all the way to the horizon! :slight_smile:

Say you put a square room with 4 doors in the level. When you start it will spawn 4 rooms, and they spawn other rooms, and they spawn…

If you use a token, it stops this sort of stuff.

The start room has a token of 2, say, and gives each of the spawned rooms a token of 1. Which means they pass a token of 0, and the spawning stops.

Does it make sense? The player is still triggering it, but not with a massive collision sphere, but rather just walking into a room. When they walk into a room, that room gets a token to spawn.

Kind of, I don’t know how infinite generation as I move would work then