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.
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.
I recently had this issue, in 5.5, and came across this post. I tried to use AnimInstance->OnPlayMontageNotifyBegin.AddDynamic inside of a behavior tree task and the notify never fired.
My solution was to create a custom UAnimInstance C++ class and make this my base class in my Animation Blueprints.
I implement the function in the .cpp file like this. In the NativeInitializeAnimation function I add it using AddUniqueDynamic.
void UBOJ_Animation_Instance_Base::NativeInitializeAnimation()
{
Super::NativeInitializeAnimation();
// Bind our notify function so it triggers whenever a Montage Notify begins
OnPlayMontageNotifyBegin.AddUniqueDynamic(this, &UBOJ_Animation_Instance_Base::HandleMontageNotifyBegin);
}
Lastly I provide the HandleMontageNotifyBegin function that is called.
void UBOJ_Animation_Instance_Base::HandleMontageNotifyBegin(FName NotifyName, const FBranchingPointNotifyPayload &BranchingPointPayload)
{
if (NotifyName == TEXT("Damage"))
{
UE_LOG(BOJ_AI, Log, TEXT("Damage notify begin fired!"));
}
}
All montages fire all notfy’s within in them every time. Hope this helps someone that comes across this post in the future.