an easy way would be saving the already created generated Numbers in an Array. Then iterate through the Array
every time you create a new random number and check if you already had that number. If yes, generate a new random number, if not, use it:
Fiddle it between the SpawnItem and SpawnActor node.
I did not add your SpawnTransform stuff, since that would not fit into the screen. And i added a small logic that makes sure the Timer is not running endlessly. Because you started it looping, but you never stop it.
It now stops as soon as the Integer Array has all numbers once. Since the RandomInteger Node creates numbers from 0 to Max-1, you will get 0,1,2,3.
That means we are done when the Length of the Array is >= 4. Or other way round, we are NOT done, as long as the Length of the Array is < 4.
Although extremely grateful for your quick response, i am extremely unsure on how to replicate this within my current level blueprint! I do understand the methodology behind this, just am unsure how to implement into current build! Here is what i have so far…
Thinking about it… Is there an alternative to the Random Integer? If i could just run through the array from 0-4 and then stop the timer, this could be as easy way to ensure no duplicates?
SO just run through the array in a chronological order rather then randomisation?
Well, you asked for random numbers. If you don’t need them to be random, then you can just use a For Each Loop for the Item Array 2 Array and spawn the Array Element in each Loop Iteration.
I don’t actually understand what problem you have with the highlighted code. Connect the Integer Array Element with the upper Input of the EQUAL node, and the New Random Integer with the lower Input.
Probably a better way of naming posts, something like a standard of some kind would be awesome. This was really hard to find even though I was looking for this exact thing for 6 hours…
Here is a simple function that will de-duplicate an array (of vectors in my case but the idea is the same for other types).
We have an input variableRawArray to plug our original array into.
We have a local variableWorkArray that starts empty and then holds our data while the function operates.
Finally we have an output variableCleanedArray which we can use out in the rest of our code.
We clear WorkArray straight away, in case data got left in there somehow.
We use a ForEachLoop to iterate through each item in RawArray (our input variable) and IF that item is not yet in WorkArray we Add that item into WorkArray
After we are done iterating, we Return Node, making sure to plug WorkArray into the CleanedArray slot on the Return Node.