AnZy_03
(AnZy_03)
June 22, 2023, 6:41am
1
Hi I am trying to play a montage from C++ and trying to detect when it is stopping but it doesn’t seem to call the callback function. It was working before and I haven’t changed that part of the code at all. I am clueless as to why is this happing.
This is assigning code
animInstance->Montage_Play(SelectMontageToPlay());
animInstance->OnMontageEnded.AddDynamic(this, &UAttackerComponent::OnMontageEnded);
This is my code at the callback function
void UAttackerComponent::OnMontageEnded(UAnimMontage* DelegateMontage, bool isInterupted)
{
LOG_SCREENMSG("Montage Ended");
isMontagePlaying = false;
animInstance->OnMontageEnded.RemoveDynamic(this, &UAttackerComponent::OnMontageEnded);
}
And this is are my logs
I can see my montage playing.
If someone has any insight as to what might be happing it will be really helpful.
Thanks in advance.
3dRaven
(3dRaven)
June 22, 2023, 8:29am
2
AnZy_03:
OnMontageEnded
is OnMontageEnded
marked as a UFUNCTION? It will throw an error if it’s not and omit triggering the callback
This works on my project
.h
UFUNCTION(BlueprintCallable)
void PlayMontage(UAnimMontage* montage);
UFUNCTION()
void OnMontageEnded(UAnimMontage* Montage, bool bInterrupted);
.cpp
void AMyPlayer::PlayMontage(UAnimMontage* montage)
{
GEngine->AddOnScreenDebugMessage(-1, 1, FColor::Yellow, montage->GetName() + " started");
GetMesh()->GetAnimInstance()->OnMontageEnded.AddDynamic(this, &AMyPlayer::OnMontageEnded);
GetMesh()->GetAnimInstance()->Montage_Play(montage);
}
void AMyPlayer::OnMontageEnded(UAnimMontage* Montage, bool bInterrupted)
{
GEngine->AddOnScreenDebugMessage(-1, 1, FColor::Yellow, Montage->GetName() + " ended");
GetMesh()->GetAnimInstance()->OnMontageEnded.RemoveDynamic(this, &AMyPlayer::OnMontageEnded);
}
3 Likes
AnZy_03
(AnZy_03)
June 23, 2023, 4:13am
3
Thank you! I think I should have slept early that day.
Cheers!
system
(system)
Closed
July 23, 2023, 4:13am
4
This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.