Play a Flipbook after another one

Hi!!!

The question is simple, the answer … I do not know :stuck_out_tongue:
I’m want to play an animation when another animation stops.
Example:

  • Play a flipbook whith a man dancing.
  • When the flipbook is finished play another flipbook with the man jumping.
  • When the last flipbook is finished play another flipbook with the man… i don’t know… crying XD

How’s the best way? (I was deselect the loops)

Thanks! ^^


EDIT:

I’m thinking… maybe I need to create a integer variable. On Tik event do a Switch. If the variable is 0 set “fliipbook 1”, If the variable is 1 set “flipbook 2”, if variable is 3 set “flipbook 3”. Is that OK?

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.

Thanks for your answer, it is very complete! It’s not Blueprints but I understand the idea. I’m going to try it right now

Great, if it does work, then please mark as ‘answered’ for other users :slight_smile: