i know how to create a AnimNotify, and in my AnimBlueprint, i am using these Notifies to call functions in my PlayerController (AnimNotify Event -> Blueprint -> Call function on playercontroller). Now, for some actions i would like to play a Animation Montage directly from code; This works correctly so far.
But i got some notifies in my Montage, and now i simply dont know how to trigger a function call on my PlayerController for that Notify, as i dont have a blueprint in the montage to do this job for me.
If it would only be to get the PlayerController-Reference inside the code, this wouldnt be a problem
To elaborate a bit more on this:
I got an AnimationBlueprint with stuff like idle-walking-etc.
Now, for Attacking i wanted to have an override of the current animation, which is possible by using an AnimMontage and call it from the code directly (So i.e. RightMouseClick -> PlayAnim(AttackAnimMontage)).
Inside that anim-montage i got a Notify for the actual impact of the attack; And at exactly that time i want to deal the damage to the targeted Actor.
The question is now, how the link between the AnimNotify in the AnimMontage and the actual callable in the Code (in PlayerController) is done.
Within the AnimationBlueprint it’s easy, cause i can use the blueprint event for the animnotify, get the playercontroller and call the function. But how can i get the AnimNotify from the AnimMontage?
Looking at api documentation for TriggerAnimNotifies, particularly the part in the source implementation:
“UFunction* Function = FindFunction(FuncFName);”
It seems that if you just declare the method as AnimNotify_NOTIFYNAME (replace NOTIFYNAME with the particular notify name) in your AnimInstance subclass, it will be called, and then you can handle it on the C++ side of your AnimInstance class there immediately. I can’t test this in Unreal right now, so please correct me if I am wrong, but I am very much interested if this approach works. There is nothing wrong with 's approach, but if this works, it will eliminate the need to create additional nodes in the Anim blueprint to call your C++ functions.
I had a hard time implementing this. Incase anybody else is struggling – Here’s what I was trying to do and here’s the path I took.
I wanted a purely C++ way to control an AnimationMontage so that designers do not need to worry & so that my code is fairly modular. In my case a melee weapon is responsible for performing chain-attacks. My weapon is told to attack, and it gives its PawnOwner’s skeletal mesh an animation montage to do! So, I have a custom UAnimNotify that overrides the Notify(USkeletalMeshComponent* MeshComp, UAnimSequenceBase* Animation) method and within this method I use a delegate pattern to call some method in my Weapon, that way every weapon is responsible for handling its own chain attack! (aka, DECLARE_DYNAMIC_MULTICAST_DELEGATE pattern). I also have an FName on my custom UAnimNotify, editable from BP, so that I can tell which even occurred from my Weapon class.
Does this approach make sense? I’d really like to hear what others do. It’s a little bit annoying that I must AddDynamic link to each AnimNotify as a montage plays, and I wish I could make use of the AnimNotify_NOTIFYNAME – however I didn’t want to make a custom AnimInstance since I am in a Weapon Actor class and I think it’s appropriate for the weapon to manage all of its weapon based animations. Is this crazy? I’m not sure! Please give me some pointers! I want to learn how to manage the complexity of animations and decouple my code as much as possible.