Variable Integer Sorting

I am trying to make a map blueprint that can read different values for each floor. I need a node that takes an input integer for what floor a room is on (from a ForEachLoop) and sorts each different value into separate arrays, one for each floor. The biggest issue I am having is that the amount of floors changes according to a user defined variable. Is there a node or function I can use/make to get the desired effect?

If I get it right, each room has an index that represents the floor it’s on. When you launch the ForEach loop, you get that index and want to sort the rooms in accordance with that, right?


The number of floors is random, but is there a limit? If yes, you can simply use a Switch On Int, with enough output pins to cover the limit (if the number of floors is lower than the limit, the higher value pins just won’t execute). I don’t thick you will have dozens of floors, so that can be your choice.

The way I have the maze/dungeon set up is that there are three integer values that are editable in-editor, a width (x), a length (y), and a height (z). On begin play, the maze is generated with rooms filling those dimensions randomly. For example, I can have it set to Width 4, Length 4, and Height 100 to generate a maze with sixteen rooms per floor and one hundred floors. I want the blueprint to find what kind of rooms and what arrangement they’re in, for a given floor.

I’m confused how this is a “sorting” issue. If someone enters, 10x10x10 you get 100 rooms per floor and 10 floors correct? And you want a blueprint to tell you that information based on what the user input? I am confused or you want to end up with 10 arrays of 100 rooms, 1 array for each floor?

Okay, let’s say you have a tower 4x4x100. How are rooms generated? The generation probably starts from the bottom or from the top, I assume, so why don’t you just take those width and length, multiply them, and in the course of room generation you can sort them out: first 16 are on floor 1, second 16 is on floor 2, etc.


Alternatively, is the rooms’ size always the same? Can you just get the rooms by their Z location?

The blueprint finds all the locations for the rooms and puts them into an array. Then it picks a random location from that array, adds a child actor component at that location, then sets that component’s class to one of thirteen identically sized rooms and removes the chosen index. This loops until the array is empty.

I want the blueprint to know how the rooms are arranged so a widget could reference the variables for each room and create an accurate map for a given floor using texture 2d variables held by the room actors.

I don’t get it. If you put a random room out of 13 into every location, why do you need to get a random location? I don’t think double random will be any more random than single random. You can easily start from the bottom with the same result.

I couldn’t think of a non-random way to spawn the rooms at the time. It does have the same effect so I don’t know how much it matters. If I can find a way to break the location array into separate arrays based on the Z value I should be able to accomplish what I’m trying to do.

You should take a look at how the locations are organized in the original array. I guess there must be a way to rearrange the array by Z location.

Or you can find a room with the lowest Z value in the array, then you get all the rooms with the same Z value, add them to a separate array and remove them from the original array. Then you do the same again and again, until the original array is empty.