Ok so, I want to have my character play a crouch animation while the crouch button is held down and stop the animation when it has finished (no looping). When I release the crouch button I want to play an uncrouch animation and as soon as that animation has finished, I want to revert back to my idle/run animations (with looping) ect. (I’ve tried multiple things but there is little to no info online that tells me how to check when my animations have finished)
Even with the code as it is right now for whatever reason, after pressing and releasing crouch once, all my standard animations (running/idle/jumping) stop looping… The problem seems to stem from the uncrouch function as if I release the button before theI have absolutely no idea why that is. Especially after setting looping back to true after the uncrouch function finishes. Any help is appreciated!
Yup! it was great! Finished 100% However, some of the setups I’m trying to do in this project weren’t necessarily done in the course which is ok but It just means a little more researching for me and asking around.
I ask as delegates are shown in the course. The signature for OnFinishedPlaying is void () so you would have
// within class definition in the header
UFUNCTION()
void FinishedAnimation();
// Adding
GetSprite()->OnFinishedPlaying.AddDynamic(this, &ASonicWorldReimaginedCharacter::FinishedAnimarion);
// Removing
GetSprite()->OnFinishedPlaying.RemoveDynamic(this, &ASonicWorldReimaginedCharacter::FinishedAnimarion);
Right now, I’m testing the add dynamic event using the UE_LOG. For some reason, even when activate my crouch function, the Text never appears. Maybe there is something I’m not getting…
// The animation to play while Crouching
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = Animations)
class UPaperFlipbook* CrouchAnimation;
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = Animations)
class UPaperFlipbook* CrouchReturnAnimation;
//Handles Crouching
void Crouch();
void UnCrouch();
UFUNCTION()
void FinishedAnimation();
in the cpp file I have:
//Crouch (This Portion goes into the SetupPlayerInputComponent Function)
PlayerInputComponent->BindAction(“Crouch”, IE_Pressed, this, &ASonicWorldReimaginedCharacter::Crouch);
PlayerInputComponent->BindAction(“Crouch”, IE_Released, this, &ASonicWorldReimaginedCharacter::UnCrouch);
void ASonicWorldReimaginedCharacter::Crouch()
{
// Are we crouching?
GetCharacterMovement()->Crouch(true);
GetSprite()->SetFlipbook(CrouchAnimation);
GetSprite()->OnFinishedPlaying.AddDynamic(this, &ASonicWorldReimaginedCharacter::FinishedAnimation);
}
void ASonicWorldReimaginedCharacter::UnCrouch()
{
//This Section is a WIP
GetSprite()->OnFinishedPlaying.RemoveDynamic(this, &ASonicWorldReimaginedCharacter::FinishedAnimation);
//GetSprite()->SetFlipbook(CrouchReturnAnimation);
//GetCharacterMovement()->Crouch(false);
}
These would be the essentials to get started with it. I’ll note that I am using the paper character class so I have the built in idle/run animations as well
Does the sprite have to be not looping for it to work?
I tried to do this in a new paper2d starterproject but it’s also not working… This time I called the function on tick.
Ok so when I add the function to the jump release action, it works perfectly. Which tells me something with OnFinishedPlaying is failing. Can you tell me what OnFinishedPlaying is supposed to do by chance?