How can I make a random idle animation play after a period of time? I have set up my animation blueprints as shown, but I am not sure how to go about counting the time spent in the idle animation and selecting and playing a random animation out of the five available. Can anyone help?
Edit: My real difficulty is counting the time spend in the animation idle1. I have tried using currenttime(idle1) but this resets after four seconds, which is the length of the looping animation. How is it possible to count a total accumulated time?
I’m sure there’s a much better way to do this, but what I ended up doing was add a Notify event to the normal (common) idle animation. In the Animation Blueprint, I react to this event by incrementing an integer variable starting out at zero. In the transition from the normal idle to the special idle, I then included the condition that this variable must be greater than a given number, so that for example the normal idle must have played at least 10 times before I allowed a change to the special idle. I then added a different Notify event to all other animations and in the Animation Blueprint reacted to this event by resetting the variable to zero, so the character would always have to play the normal idle 10 times in a row before using the special idle.
Thanks! Using this principle I have now got my character to play a specified idle animation after 30 seconds. Do you know how it would be possible to play a random animation from a selection? I have tried using a conduit but I cannot quite make the random selection work
Thanks for the reply. What you just posted is actually how I had created my blueprint, I did not worry about notify events. I also worked out how to play a random animation. I did it as follows: Once the idle time reached a specified amount, create a random float between 0 and 1. I then play one of five animations by specifying a range in the animation transition rules, eg: if the random number is between 0 and 0.2 then perform idle animation 1. If the random number is between 0.2 and 0.4 then play idle animation 2 etc…
I don’t know right now, but I’ll try and see if I can find out something as that’s something I’d like to know as well.
Incidentally, while searching I stumbled upon a different solution to your problem, which I like rather better than mine:
“I setup a blueprint to count idle time by accumulating Delta Time X in the AnimBlueprint event graph anytime when speed is zero. After the idle time reaches a certain number of seconds I set a boolean value that activates a node in the AnimGraph and I reset the idle time to start counting again.”
(posted by Waves here: https://answers.unrealengine.com/questions/135427/how-to-play-random-multiple-idle-animations-using.html)
That’s a good idea, though it could quickly get unwieldy if there are a lot of animations.
Meanwhile, I’ve discovered how Blend nodes work. If you pass a random int variable into a Blend Poses by int node, that handles random animations pretty nicely. The only issue is limiting the random number to the number of animations, which has to be hard-coded in the AnimBlueprint.
I’m also really excited to learn that it’s apparently possible to blend animations by custom enum values, so that it should be possible to use certain states (such as flying/swimming/…) or character properties (like monster type) to decide which animation to play. Again, that could quickly grow really large but is probably still better than a complicated graph structure.
Another often suggested solution to the task of playing random animations are Anim Montages, though I still haven’t understood how exactly that’s supposed to work. I think Montages are more applicable to animations triggered by certain events rather than basic background idles.
Anyone still looking for this:
Use montages. Set the montage bone group, have the random idle animations as montages, and in the anim BP track time spent speed >= 5 (thats what i use, i dont like to use 0), when time = allowedIdleTime: Use a select node, random float between # of Idle animation variations as the index, animation montages as the input, selected random animation as the output, voila.
Hope you understand, im about to set something exactly like this up so I’ll repost shortly with a pic
simply use “Random Sequence Player”
can u post the image? would be very useful
Thanks! This should be the answer, its simple and works perfectly.
hey, where are you getting that idlenum? ive poked and prodded but cant seem to find a way to extract the idle time from my blueprints…