How to listen for UAnimSequence notifies in C++

I’m looking for a way on how to execute any C++ code on animation notify.

I have AnimSequence in the content browser in the editor with two notifies. As seen below:

I sam something that looked viable here: [SAnimNotifyPanel.cpp][2] but… now I see these methods are only available with the editor (surrounded with #if WITH_EDITOR).

Any variables that might be useful are protected, so maybe I’m supposed somehow to create a subclass of UAnimSequence? But then how would I set it to get all the stuff that I’ve set in the editor.

Note that I’m interested in C++ only solution, blueprint is not an option here, as I’ll have to do many customizations later on.

You have to create a subclass of UAnimNotify and override the Notify method, note that this method has the USkeletalMeshComponent and the UAnimSequenceBase so you can actually have direct access to the animation instance by doing a simple cast like this:


This notify will show in your animation sequence when you want to add a new notify. Then from the anim instance you can call any callback method you want or just do your stuff on the custom notify you just created.

P.D. as a side note if it’s annoying having to create a class for every notify you have I suggest you think about creating a single notify class with an editable parameter that you can access from the anim sequence, then you can check on this parameter to call different callbacks on your notify class.

Hope this helps.

Thanks, that sounds brilliant! I can see it working, thanks a lot!

Edit: I had some problems where my new class wouldn’t be placed in context menu. The reason for that was editor silently breaking recomplication of c++ classes (in VS compilation was successful, but for editor it was breaking because of .h files that were no longer in my project).

Oh that’s really annoying! I had the same issue and I took like an hour (first time I come across that) to finally clean up the editor’s connection to the header files.