XaiJu
Megan Fox
Megan Fox

patreon


Looping animations with non-looping in/out anims

(this would be the March code post a few days late, sorry about that! GDC and the halo around it kind ate time, heh)

Imagine you want to animate a bird unfurling their wings, flapping them or holding them out to glide for (some gameplay-variable amount of time), and then gracefully fold them back up. You're probably not making a bird game, but that kind of prepare -> do thing for a while -> recovery flow is super common in games.

So, how do we do this in Unreal?

Easily, it turns out! Well. Once you understand the trick. First of all, to set the stage, we're just doing this in a state machine that's applying things additively. Cool? Cool.

The work happens in that WingsHandler state machine, which looks like this:

Couple of things to note here. See how all the transitions leading to folding are red? That's because I made a shared transition that they all use. If I remember correctly, I didn't make the transition back to Unfolding shared because of some fucky bug in how shared transitions work. It'll yell at you if you try to make shared transitions both ways. Try it. Maybe they'll have fixed it. Anyways!

Also I'm not bothering to show what's inside each of these states, since they're all literally just, this. Only difference is the animation being used, and whether you toggle the lil loop animation option. You want the looping animations in the middle to loop, and you want the non-looping ones to, not loop. Heh.

The magic is in the transitions, which look like this:

Basically what we're saying here is, the transition from "Unfolding" to "Gliding" only becomes valid after the "Unfolding" animation has finished playing. Or at least, played up to the point where we want to start cross-fading it.

The states from gliding/etc to folding are much simpler:

When we enter the wing-folded state, transition into the Folded animation state. Simple, right? Incidentally, what this means is that this state machine actually idles in the "folded" state. You know that link I made from Unfolding direct to Folding? This is why. We idle in Folded state, and then when we need to trigger an unfold-and-flap, it first transitions back to Unfolding, like so:

And then it just plays out from there, like you'd expect.

So that's a lot of logic, but see? It's really super simple. The whole trick of it is knowing that you can do fancy transitions, and that those length-of-animation and length-of-transition nodes exist in the first place.

This can be used to do WAY cooler stuff than wing flaps. So, have fun!

Looping animations with non-looping in/out anims

More Creators