Randomize animation play?

Hello!

So in this setup, I need to trigger an animation by a Key Event, that will play on a random character.

My BP is set up like this already:

To clarify, the clones in the background are supposed to follow the main player’s animations, and I want a way where they can start falling down at random.

Falling down to the ground or falling down to the infinite? With a new or the same animation?

To the ground using a new animation.

Is the new animation a new state or a new Animation BP.

If it’s a new animation BP then, in the player event graph:

Press R, and it will randomly select a character and set the new animation.

Thank you! I’m only starting to learn BPs and can’t seem to be able to find/add that “Target” socket?

Take a wire from the output of “GET” and select “Get Mesh”:

In “Get All Actors of Class” make sure to select the characters’ class.

That did it, thank you!

So the Get Mesh node won’t show up unless I uncheck Content Sensitive…

And when I do, I get this node which only has one socket still

236263-get2.png

I know I’m probably doing something wrong, just can’t figure out what…

Could it be that I got the wrong “Get” node?

Hello again :D. One last thing, and I’m sorry to be so greedy with your generosity; Would there be a way to make sure that once a character has played the death animation, it stays down and doesn’t jump back up when I trigger any of the other animations? I explain it a little better here: Subtracting clones from group animations? - Character & Animation - Unreal Engine Forums

There are several ways. Here is one:

If the number of characters is the same throughout the game and their number is fixed (not continuously spawned), then put all actors in an array.

Then every time you press “J” to randomly select a character, instead of using “Get All Actors”, you will randomly select an actor directly from this array, play the death animation and then remove the character from the arraw, using the node “Remove”.

(I can’t show any BP, because I’m not at home.)

How are putting the characters in world? Are you creating them at run-time? Or are they already in the world before you start playing? If so, then:

And then:

Having trouble adding the characters to an array. It won’t allow me selecting the character “homegirl” in the Array Elements field. Thinking I’m selecting the wrong variable type…

Thank you for the reply! My issue is creating an array that carries the characters. The characters are already there before play, and whenever I try to add them to an Actor-tpe variable, it doesn’t work. They simply won’t get added to the Array Elements.

Since the characters are already in the world, just do it as in the first pic.
As soon you start playing, the array will be automatically populated, so no need to set size or add them manually.

1 - at the “Begin Play” event:

1.1 - attach a “Get All Actors of class”

1.2 - select the correct “Actor class”

1.3 - drag a wire from “out Actors” and select “promote to variable”

1.4 - rename the newly created array variable as “xxx” (whatever you want)

2 - at the “Z” key event:

2.1 - remove the “Get All Actors of class”

2.2 - from the list of variables, drag “xxx” and select “get”

2.3 - connect that to all places places where the array is needed:

Set it up like this, and it isn’t working :confused:
There’s a couple of Get and Remove nodes available, and this is the only configuration that is compatible. What am I doing wrong? :’(

Again, very very thankful for your patience!

Tried both ways (see screenshots) and it does seem to work, but not the way I want. Some characters do get removed, but some of those are the ones still standing (have not played the death animation, and thus unable to die). I just want the characters who have died to stay dead (lol) and to still be able to randomly kill off the remaining ones.

Sorry, my bad. There was a error from my part.

Your second pic is right, but requires a little correction.
When “Remove Item” is called, it gets a new random number, and therefore it can select another character other than the one that died.
So the solution is to save the random index in the first time in a variable and then use it for both the “Get” and the “Remove”. Something like this:

Sorry for the design.

That shouldn’t work.

That “Set” should be connected to the exit of “random integer” in order to save the generate random int, and the output of this “Set” connected to the “Get” and to the “Remove”.

The way it’s now, the “Set” is doing nothing.