Duplicates Within Random Array

Hi Guys

I have created an array of props then spawn onto a conveyor belt in a random order.

Everything is working as intended, however i do not wish duplicate props to spawn. How can i go about doing this?

I am using the ‘random integer’ function, which does serve the purpose of the random side but i cannot see an option for avoiding duplicates.

Any Ideas?


Hey there,

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…

Thanks in advance

i will try this right away. Thank you very much, this has been extremely helpful of you! :slight_smile:

Hi ,

I have followed the blue print but am not sure how to add the highlighted bit (as shown in the image below) ‘==’

Thanks again for the help!!

![alt text][2]

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.

Managed to get it working! Was using ‘==’ instead of ‘=’ Thank you so much you are a live saver!!! Amazing feedback cant thank you enough :slight_smile:

Awesome (: Make sure to accept the Answer at the top left of my Main Answer Post! Then everyone can see, that the question is resolved.

Your RNG saved my life!

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 variable RawArray to plug our original array into.
  • We have a local variable WorkArray that starts empty and then holds our data while the function operates.
  • Finally we have an output variable CleanedArray 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.