First things first, let’s take a look at that documentation, shall we? ^^
This is the UPaperFipbook:
https://api.unrealengine.com/INT/API/Plugins/Paper2D/UPaperFlipbook/index.html
Here you can get access to the duration of the animation using GetTotalDuration(). If I’m not mistaken, then you could initiate a timer that is set to conclude after the length of the animation.
This is the UPaperFlipbookComponent:
https://api.unrealengine.com/INT/API/Plugins/Paper2D/UPaperFlipbookComponent/index.html
It boasts the function OnFinishedPlaying() which is called when a non-looping animation finishes.
Here’s an example I found in another answer of this being used:
So, you would call your ChangeSprite() function using OnFinishedPlaying(). You could even store the next animation to play elsewhere and feed it in as an argument, perhaps even with the option to exit out of the current animation early like so:
.h
// Function bound to USpriteComponent::OnFinishPlaying
UFUNCTION()
void FinishPlaying() {
PlayNextAnimation(NextAnimation)
}
// The next animation to be played
UPaperFlipbook* NextAnimation
.cpp
GetSprite()->OnFinishedPlaying.AddDynamic(this, &MySpriteCharacter::FinshPlaying);
// System for choosing next animation - currently a crude switch statement
void PickNextAnimation() {
switch (int) {
case 1:
NextAnimation = JumpAnimation;
break;
case 2:
NextAnimation = DanceAnimation;
break;
...
}
}
// Calling this before the end of the animation will force a change.
void PlayNextAnimation(UPaperFlipbook* AnimationToPlay) {
GetSprite()->SetFlipbook(AnimationToPlay);
}
I’m sorry I can’t blueprint this right now, or even test the code for that matter, but hopefully this could get you started!
If you need more help, then just ask! I don’t actually have time to put anything together right now, but if needed I certainly can try in the near future.
Regarding deciding which animation to play: take a look into state machines. UE4 has a decent animation state machine tool for 3D animations, but I’m currently unaware of whether there is a sprite state machine built into the engine, or whether you would have to concoct your own.
A switch on index would work too, however, though it is advisable to only use such a system if it is relatively simple.