AddDynamic for a montage not working

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
image

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.

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

Thank you! I think I should have slept early that day.

Cheers!

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.