How to get random actor of all actors without repetitions?

Hello everyone, i’m making puzzle game and i want to make hint mechanic which marks one random puzzle element as “clicked”. I want to get one random puzzle from all actors of the type and i made something like this:

It kinda works but, i can get the same puzzle more than one time. Is there any way that i can force it to give me different puzzle everytime? For example: There is 10 puzzle on level, I use hint first time, it works fine everytime, but when i use hint second time, there is a chance that the “Hint2” Event applies to the same puzzle for which the first hint was used.
On the left side there is only trigger and “Hint2” event is changing mesh, marking puzzle as clicked, adding points to score etc. I think it doesn’t really matter.
I would be really greatful for every tip and answer. Have a good day everyone! :slight_smile:

Store the result of Get All in variable and shuffle - do it only once on Begin Play. Now you have a randomly ordered array:

Since the array is randomised, you can get Next element instead of a random one. Once you have the element (Print - your Hint goes here), increase the iterator.


As a bonus, you need to run Get All only once.

It works perfectly fine. Thank You so much! You saved me few days of desperate thinking :slight_smile:

PS. For some reason i had to sign -1 value to Iterator, if it’s 0 and i want use hint for last actor it doesn’t work, but anyway your help was huge for me.

Are you increasing it after getting the element? Getting index -1 from an array usually means a very bad time…

Yes, I’m increasing it after getting the element. To be honest i don’t even know why it works like that. I’m begginner to blueprints. When iterator is set to 0 i’m actually getting 2nd element from array. When iterator is set to -1 im getting first element from array. I even set it to -2 to just find out what will happen, and then i’m not getting any element from array. As i said i’m just learning and i bet you’re 100% right about all this, but in my case it just works like that.

When iterator is set to 0 i’m actually
getting 2nd element from array.

Can you post the script? I feel something is done in incorrect order…

To demo what I mean:

Image from Gyazo

The first index you’re going to pull from the array is equal to the int. If the int is 0, you’re pulling 0. The int is increased later on. Here the array has 4 elements - 0,1,2,3

You are right! I think i know what happened in my case. After increasing iterator value I made custom event which was using object from “GET”. But when the event was executed the interator value was already increased so i ended up with actually using 2nd element instead of 1st. You were totally right, i messed up with order. When i moved my event before increasing interator it works fine with interator set to 0. I really appreciate all Your time to help me. You are so kind and helpful :slight_smile:

Ah, that make sense! Glad you got it to work the way you needed.

Good luck with the rest!