Random array picking of multiple Blueprints

If I have many copies of one Blueprint in my level, and I want to pick a random one of them from an array and make it do something, how could I do this?

Something like this could work, if they are all the same class:

edit: if you already have them in an array, then obviously you don’t need the Get All actors of class

If you do a get all actors of class, get the length and plug that into the max value of a “Random Integer in Range” node, then plug that into the index value of a “get” array node, you will achieve what you are looking for.

&stc=1

[=Mosel3y;220837]
Something like this could work, if they are all the same class:

edit: if you already have them in an array, then obviously you don’t need the Get All actors of class
[/]

You beat me to it :slight_smile:

I did what you did (except I replaced the Print with a simple Set Actor Location, to make whatever random one picked float up so I can see it), but it doesn’t seem to work sometimes. I added another part to check the random item for a Boolean variable, and supposedly it should check to see if the variable is false, and if so, it raises the object and sets the variable to true. However, it doesn’t seem… accurate. It will raise some of the random items multiple times when it shouldn’t allow this, and some of the items it doesn’t ever raise. I have no idea why it’s doing this and I can’t put up a picture currently :frowning: .

i havent done that, but why not having the gamestate or gamemode or a Manager Class holding an array of your actors references? I mean event construct of your blueprint will add a new item to that array. Would mean a bit of performance on Loading game but will save you the impact of Get all actors of class during runtime.


Here is the blueprinting. The blue lines from each picture going off the screen are the same lines. I can’t figure out where the error is, it still allows actions for tables that should be unable to be acted upon. I’ve turned the boolean variable to a default of true for experimenting with it and it works fine then - the problem must be with changing the variable of the Target.

Hello,
I deleted last post where i mistaken random int in range instead of random int. I got recently weird issues with random int and it solved when i set a variable once and use this variable instead of output to be sure always have the same random.

Edit : Not weird if you consider that all non exec nodes are called by each exec node. Then a different number each time.

Well I have it all done and working (did it a day ago but just posting), consider the matter closed.