Hey, I’m a designer and I work with Unity professionally. I’m trying to learn Unreal Engine 5 blueprints by implementing a simple town random generator out of simple blocks, according to a design I prepared for myself.
I’ve run into the following problem:
I add the mesh for School into blueprints. It can generate offset to the Market by the listed values.
I shuffle the values to make it random.
This part works, the School block generates properly.
Now for the part that I can’t get to work as I’d like it to
I add the mesh for Church into blueprints.
I want the Church to use the same Array of locations as the School, minus the one the generator chose for the School, so that the two blocks don’t overlap.
I tried putting Remove Index here, but I can’t figure out how to connect the nodes so that it would choose everything but the location removed.
I’d be happy if anyone could explain to me where the error in my thinking is.
This is the result sometimes (yellow-School, red - market, blue - church):
Maybe an array to store placed buildings? All it needs is its grid location and building type, then each time you place a building for each loop the array. If location taken go back and geberate a new one until its free. Theb add the new building to the array.
High500 is right,
if you have an array of locations , add an a booleans too.
Get random number between 0 and max length array location.
Got position 4 ?
check if boolean array position 4 is true?
is already used, get another random number.
Boolean array position 3 is false?
nice, spawn churc at arraylocation 3 and set boolean 3 true
To understand the issue here, we need to first understand how “Pure Nodes” work!
Pure nodes are the nodes without the White Execution Pins. Pure Nodes execute every time you access their outputs. For example, the output from the Make Array node is connected to three different nodes, each of those nodes get a COPY of the array. for example, you’re shuffling a copy of the array and getting a random value from a different copy of the array.
Similarly the Random Integer in Range node outputs different random values for each output wire, hence removing the index won’t work, you would be removing a different index than the one you just used.
So what’s the solution? store the outputs in variables and use those variables instead.
Now, how to solve the overlapping issue?
Store the Make Array output in a variable (You can right click the output pin and choose promote to variable).
Shuffle that array variable.
Store the output of the Random Integer in Range node in a variable.
Use the random number variable as the index to get a location.