How can I listen for an anim notify event on C++?

I have a montage with a custom notify and I have inherited the UAnimInstance to handle my animationBP from code, that being said I have access to the FAnimNotifyEvent but how do I declare a callback on C++? On the BP you just add a new “Anim notify event” and that’s it, how can I do the same on code?

P.D. I don’t want to add anything on my blueprint for this, how do I make the callback only on code side?. I think I could create a subclass of UAnimNotify (or UAnimNotifyState) and override their methods but then the callback implementation lacks the UAnimInstance’s variables I have, so far I can only think about exposing the method I want to call on C++ for my BP to call it whenever the notify fires.

If I understood the question correctly, this could help:

I encountered that same question before, he is adding a notify from code but he has an inherited class of UAnimNotifyState where all the events fired by the notify are handled, and as I pointed out I want to be able to create a callback on my UAnimInstance custom class (like you would usually do on a BP), if you know of a way to connect the event from the UAnimNotifyState to the UAnimInstance callback please let me know.

If you derive from AnimNotify, the first argument to the callback (Received_Notify) is USkeletalMeshComponent. You can get to your anim instance from there.

Oh really? didn’t notice that, thanks!
Edit: I just did some refactoring on my code and this totally worked, thanks again for your help :slight_smile:

On my case I was looking for:

UAnimInstance* AnimInstance = /* ... */;
if (AnimInstance)
{
	AnimInstance->OnPlayMontageNotifyBegin.
	              AddDynamic(this, &UBHAbilityTask_PlayMontageAndWait::NotifyBegin);
	AnimInstance->OnPlayMontageNotifyEnd.AddDynamic(this, &UBHAbilityTask_PlayMontageAndWait::NotifyEnd);
}

void UBHAbilityTask_PlayMontageAndWait::NotifyBegin(FName NotifyName,
                                                    const FBranchingPointNotifyPayload& BranchingPointPayload)
{
	/* ... */
}

void UBHAbilityTask_PlayMontageAndWait::NotifyEnd(FName NotifyName,
                                                  const FBranchingPointNotifyPayload& BranchingPointPayload)
{
	/* ... */
}

Did you manage to get these callback functions with AnimNotifyState?

One of the 2 options gives you no guarantee that the notify would ever fire in the first place.
(Cant remeber which).

The Notify docs oage should have clarity on that.

Essentially only notifies that are created and set between abimation state machines are going to ever fire 100% of the time.

So, not that implemeting a c++ function for it is completely pointless, but do consider the fact you won’t necessarily ever get a callback to fire…