Hullo,
I’ve got another animation question.
I want to run an animation montage from C++, which I can now largely do, but I want to run a C++ function when it finishes.
There are two primary ways to do this.
I can do it with a timer with something like the following:
void AMGCharacter::OnPrimaryAttackPressed()
{
bIsPrimaryAttacking = true;
float duration = PlayCombatAnimation(PrimaryAttack);
PlayingAnimation = PrimaryAttack;
GetWorldTimerManager().SetTimer(TimerHandle_OnCombatAnimationFinished, this, &AMGCharacter::StopCurrentCombatAnimation, duration, false);
bIsCombatAnimating = true;
}
Or I can do it with a notification.
To do it with a notification right now, I can make a notification in the animation and then wire a Blueprint to call a C++ function to finish the animation.
Two questions:
- If I define a custom UAnimNotify type, such as
UAttackEndedAnimNotify
, how would I get the pointer to this notify, if there is one, from the animation montage and set a delegate for the call on notify? Or should I set up for this notify to always get the mesh, then the character, then cast to my character type (is this possible), and always run a particular function form there? - If I can set up the notification from C++, would it still be preferably to use the timer method? This is how it’s done in the ShooterGame. It’s much simpler, but I’m not sure it would be better (or at least I’m not sure what I’d be missing out on).