Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

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?


Product Version: UE 4.10
more ▼

asked Apr 17 '16 at 02:18 PM in Blueprint Scripting

avatar image

2 1 3 6

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

3 answers: sort voted first

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:


more ▼

answered Apr 17 '16 at 06:35 PM

avatar image

6.8k 333 185 470

avatar image Mag454 Apr 17 '16 at 07:07 PM

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.. alt text

Thanks in advance

blueprintarray.png (229.3 kB)
avatar image eXi Apr 17 '16 at 07:41 PM

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.


avatar image Mag454 Apr 17 '16 at 08:07 PM

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

avatar image Mag454 Apr 17 '16 at 09:11 PM

Hi Mate,

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

Thanks again for the help!!

![alt text][2]

array3.png (350.0 kB)
avatar image Mag454 Apr 17 '16 at 09:24 PM

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?

avatar image eXi Apr 18 '16 at 12:43 AM

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.

avatar image Mag454 Apr 18 '16 at 06:52 AM

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

avatar image eXi Apr 18 '16 at 11:46 AM

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.

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

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...

more ▼

answered Apr 24 '18 at 09:21 PM

avatar image

28 1 3

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

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.

alt text

dedupearray.png (256.6 kB)
more ▼

answered May 25 '18 at 11:35 PM

avatar image

1 2 2

(comments are locked)
10|2000 characters needed characters left
Viewable by all users
Your answer
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question