Play random animation from list

I have 8 characters, they all come from the CC3 and have similar bone structures. Only one of them has animations attached to it (51). They are characters for the background of a scene.

I want them to select a random animation from this set and play it, then select another animation and play that. All randomly, continuously. I plan on placing a lot of them to simulate a crowd.

I’ve been googling this for a few days but, maybe it’s just my search terms, but I’m not finding anything that remotely seems to help.

I’m pretty new to UE4, and very new to visual scripting (or scripting in general).

Can anyone help? Thanks.

Hello! Basic things can be done like that

  • Add array of Characters variable (Characters on the pic) and fill it with actors on you scene (in BeginPlay body on the pic)
  • Add array of AnimSequences variable (Anims on the pic) and fill it with anims you want to play (in BeginPlay body on the pic)
  • Use nodes from Q Input node body to get random anim, random character and play first on the second

Another option that I have used for this exact thing is to create a simple AnimBP, that just plays random slots from an anim montage.

So I create an Animation Blueprint and assign it to the character I want to use it.

Then I create an Animation Montage that is compatible with the skeleton of the character and add all the animations that I want it to be able to chose from, put each one in it’s own section of the montage and “clear” them so they all play independently. It’s also worth noting here that blending plays into this a bit depending on your animations you may want to increase/decrease the blend time. You can create a new slot name or stick to default slot if you prefer.

I then setup the Anim Graph in the Anim BP to play the slot animation that I assigned in the montage on top of my idle so that it has a nice base pose.

Then finally in the Event Graph of the Anim BP I setup the script to run the Montage, I set it to run on Begin Play and then wait a random amount of time, to help keep it more out of sync from other characters and add some more randomness as it continues. I create an array of Names for the sections of the Montage and each time I play select a random one. When the section is finished it will run the event again wait again, and so on, and so on, in a loop.

And that’s it. I found this method worked well for me, as it was low maintenance and clean, didn’t have to update anything if I added more characters to the crowd. But there are many ways to achieve the same result, you should use whatever you think is the best solution for you.

Thank you both! I will give both solutions a try and see what works best for me. :slight_smile:

Thank you both! I will give both solutions a try and see what works best for me. :slight_smile:

In your first screenshot, I don’t know where to find that.

In your last screen shot… um… wizardry? I don’t know the slightest what’s happening. heh.

Wish I could delete comments. So I think I’ve got it MOSTLY where you’ve got it. With the min/max do I have to input anything in the value ranges?
And with the Sections > Random - how would I set that up?

The min/max is up to you, all that dictates is the amount of time that is delayed between playing animations.

The sections->random is simply an Array of names that match the sections of the montage, in the case of that example they are simply titled 1-7 but could be called anything you wish, and the random node just pulls a random index from the array to select which one to play.

In case you haven’t found it, that’s simply the animation selection within the skeletal mesh component of the blueprint.

Hey Bruffhaus! Thank you so much for replying. I ended up sleeping on it and coming back the next day and it all went a lot smoother. I think I was just getting frustrated at myself.

I think I’ve got it almost exactly set up how you do, but it doesn’t actually seem to run through the animations, and I’m wondering if I have either my montage setup incorrectly or my sections variable.

My montage has lavendar coloured sections, not green. I’m not sure if this is a problem.

This is my Sections “Name” variable

and this is my overall bp

also this is my animgraph

Your Event call to start the process again is linked directly from the top pin of the “PlayMontage” function.

“PlayMontage” is a latent action (denoted by the little clock in the top right corner) the top execution pin does not wait for the latent action to complete before executing and so it would be trying to play again over the top of the existing one and restarting each time. You need to change that to only execute after it’s finished so in this case connect it to “OnCompleted” instead.

Hey thanks for that and for explaining what that does.

I’ve changed it and compiled it, but I still don’t get anything. It’ll play the initial animation set in the AnimGraph, but it doesn’t seem to play anything from my Montage.

Oh my lord.
Listen. It works and I am so incredibly thankful to you for your help. Thank you so much Bruffhaus. You’re a legend mate.

Looks like you haven’t selected a montage from the “Montage To Play” drop down in the Play Montage function

Glad to be of help! Feel free to mark the answer as accepted so it might help someone else in the future too.

I know it’s an old post but I basically do the exact same thing.

The only problem that I can’t solve is how to “blend” seamlessly between the different animation tracks in the montage, the same way we can blend two different animation tracks in the sequencer.

In my own version to things the animation just abruptly changes to the next one.