• Runtimes
  • [UE4]Playing animation with random intervals

Hey forum,

So I have two animations of Idle, the first one of character breathing and the second one of him scratching his back.

I want to play the first animation in a loop and periodically fire scratching animation and then going back to the first one.

Any ideas on how it can be set up in UE? I can do it once (first I set animation to Idle01, then add Idle02 with a delay and then add animation Idle01), but once I try to put it in some kind of loop (like for each or whileloop) it stops working.

Related Discussions
...
  • Змінено

I assume you want to do this with blueprints, correct? In that case, standard for each/while will not be of much help, as those are blocking operations.

What you can do instead is this:

  1. Queue the "Idle01" animation, set it to looping, e.g. on BeginPlay, via the "Set Animation" node Spine-UE4 Runtime Documentation: Setting Animations
  2. Separate from this, add a Delay (https://docs.unrealengine.com/latest/INT/BlueprintAPI/Utilities/FlowControl/Delay/) with a random value. Connect another "Set Animation" or "Add Animation" node to that which sets the animation to "Idle02"
  3. The "Add Animation" node will return a track entry. You want to listen for the completion of that track entry (== the "Idle02" animation). When that happens, you want to set the "Idle01" animation again. You can listen to track entry animation events as described here Spine-UE4 Runtime Documentation: Processing AnimationState Events