How to check overlap between the same actors?

Okay so I have a random room generator and sometimes these rooms clip into each other and overlap making it hard or impossible to enter the rooms, So I made an actor that sits inside of the room blueprints that is meant to detect collision between the rooms, but it doesn’t work no matter what kind of code or blueprints I make for it. The actor that checks for collisions is called the R_collisionbox and is just an actor blueprint with a box collision inside that I usually scale up to fit the size of the rooms. I have had many trails and errors and I have yet to find something that works. here’s what I have currently inside the actor.

Everywhere I looked, apparently this is the correct way to use the overlap event but it just wont fire when R_collisionbox actors collide. Off the screen I have a branch that if the actor is overlapping with another R_collisionbox actor will destroy the parent actor that the R_collisionbox resides in. If anybody knows how I can get the actor to detect collisions with the same type of actor please let me know, I’ve been stumped on this for a while.

Maybe check if the overlap event occurs at all with a print string message. You can also put another one into the cast failed pin. Try to narrow down the problem.
Sometimes little things can break blueprints. Maybe begin overlap never happens because they are already overlapping when the rooms are constructed. Weird things like that.
Then if the overlap event happens check what is overlapping with print string of its name.
That ‘is overlapping actor’ node might be double checking. You’re box causes the overlap event so you don’t need to check again if it was overlapping?

I’ve already tried this and I still can’t figure out what the deal is. The overlap event fires when the player actor walks into the collision but the overlap event doesn’t fire when the collision detector actors are colliding with each other.

Perhaps the solution might be in how you distribute the rooms. Could you share how you are generating them?

Wouldn’t that mean if two of the rooms detect each others overlap event they both would try to destroy the other room at the same time while being destroyed that moment? A bit of a mind f**

Okay so the Rooms themselves are spawned from a layout actor, which is just the level layout this is where the rooms are told to spawn and how many are allowed to spawn.

The one I have now looks like this

The layout is made up of static meshes and RRS (random room spawner) actors you can see them in the structure as the walls that have white dots and arrows, that’s where the actual rooms themselves spawn from.

I will provide a picture of one so you can see what it looks like in detail (Despite the fact it has none right now)

Now I have the code for spawning random rooms inside the RRS actor but its a little blurry because I had to fit it on my screen

If you need to I can break up the code across pictures so its more decipherable

But for the Layout code generation I did have to break it up between three pictures, But I guess it allows me to explain each part in detail.

Now the spawn rooms code begins with a branch node that allows the code to continue if the Room limit hasn’t been hit, hence why there is a node that comes back around from the end. Now the rest of the code is just getting all the RRS actors in the blueprint but I’ll explain it more in the next image

Now the code continues by getting a random RRS actor and telling it to generate a room. Then the rest of the code is just adding to the current room number so the limit branch actually works.

Now for the code offscreen its just a print string that tells me the current room number at the moment.

and that’s really the important parts of the generator, sure there’s more code but its mostly just stuff like changing the wall mesh back from a doorway to a wall if the room is removed.

I hope this explains it.

Actually if collision is detected the rooms don’t tell the other one to destroy itself but rather the overlapping room destroys itself. yeah it was much easier to do that and since I do have a room limit I can just make it that every time a room destroys itself the number will go down by how many where destroyed.

but in more detail each room has a R_Collisionbox child actor and the R_Collisionbox when it detects another one of itself colliding with it tells its parent actor to destroy itself.

Wait a minute, for some reason The code works inside the layout blueprint when I hit simulate. the rooms spawn as normal but the overlapping rooms destroy themselves and new rooms are spawned to replace them, or until those rooms aren’t colliding with anything. but when I start the game in the viewport, the R_collisionbox actor doesn’t seem to detect collision to the overlapping rooms and does nothing? how does that make any sense?

For the Collision issue: assuming the rooms have a fixed area, you could assign each a value. For example: small room = 1, medium = 2 and large = 3. So if a wall can only hold lets say 4 places: you spawn 3+1 or 1+1+1+1 or 2+1+1, 2+2, etc… You can loop select random sizes until the wall has been “filled”.

Since they are spawning in a fixed area, you can use simple math to know what room fits where without the need to check after they spawn. Like in this quick test I just did. Here the bp is randomly spawning “rooms”, it’s taking their value and placing them accordingly until all the spots are either filled or loop is done.

Yeah I understand that might be a better way to do it, but the code I have right now works fine as is, Its just the collision detector doesn’t work in viewport play but only works in the layout actor (which holds the Random room spawners) when I hit simulation

Okay, I know its been a while since this thread has last been used but I have managed to get something working so far but its still not 100%.

Now the overlap in the collision box actor will fire when it comes into contact with another actor of its class. except for when it overlaps another one, only one collision box actor will fire off the event and the other one will say its not overlapping even though it is. What did I do wrong in my code for it to not fire in both overlapping actors?

Try this in event begin play: Get Overlapping Actors | Unreal Engine Documentation or Is Overlapping Actor | Unreal Engine Documentation

I’ve tried these before and none of them really worked but I could give them another try.

If nothing works, then perhaps the solution is not checking for overlaps.

Well I see no other solution besides using collision volumes to check for overlap, but thanks for the advice.

Okay I got it working using a combination of this and the code I had previously! Thanks for the help!

1 Like