Download

Crash Course In Animation Notifies

Hi guys, happy Monday! We’re kicking off the week with an Animation Notifies blog post from Benn Gallagher over at Pitbull Studios in the UK. Enjoy!
[HR][/HR]
Blueprint Notifies

Blueprint notifies are a way to trigger some custom logic defined in a blueprint at specified times in an animation sequence or montage. The concept is similar to the animation notifies in UE3/UDK but with a much smoother workflow and zero code involved. To create a new animation notify, create a new blueprint and choose AnimNotify as the class in the ‘Custom Classes’ section of the new blueprint dialog:

Upon opening the new blueprint in the blueprint editor there will be no graph, just an empty blueprint with an overridable function ‘Received_Notify’ in the ‘My Blueprint’ tab. Implementing this function creates the event graph that will run when the new notify is triggered in an animation or montage.

To use the new notify, open up a sequence or montage, find the notify track(s) and right click. Your new notify should appear in the top section of the context menu.

Having a blueprint run some logic in an animation is nice, but it would be limited if we couldn’t give the blueprint some data to work with such as positions, colors or classes. Fortunately this is possible and is a pretty simple process. Variables created within this graph are exposed to Persona when editing a sequence or montage. They appear in the details panel when selected in Persona:

2.png

3.png

This can be used to expose any type that could normally be used in a blueprint from simple types like bools and ints to more complex actor classes. The methods of communicating with other blueprints will also work allowing animations to trigger complex sequences of events.

Event Notifies

If simpler logic is needed that doesn’t require any configurable data and is specific to a skeleton (i.e. won’t be reused across different skeletons) then an event notify might be a better option. In the same context menu that is used to add blueprint notifies is an option labeled ‘New Notify’. This option adds a notify to the track that has no data attached; only a name. Once added, any animation blueprint that is playing or evaluating that animation anywhere in the root animation graph will have access to the notify as an event in event graphs. These events work similarly to functions; execution will pass to them every time they are triggered in the animation.

4.png

Default Notifies

In the Engine content folder in Unreal Engine 4’s editor at the time of writing there are two default blueprint notifies that are available, AnimNotify_PlayParticleEffect and AnimNotify_PlaySound. These notifies are created exactly like the blueprint notifies discussed above and can be a great starting point or reference to setting up your own custom blueprint notifies.

Notify States

Notify states are slightly different and are best suited to situations in which it would be beneficial to have a start and a stop for some functionality or when a continuous update tick is needed when the character is doing something specific. Creating notify states is similar to creating a blueprint notify except when choosing the class to derive the blueprint from, pick ‘AnimNotifyState’.

Just like the blueprint notify, the functionality of the notify is created by implementing functions except there are three this time, ‘Received_NotifyBegin’, ‘Received_NotifyTick’ and ‘Received_NotifyEnd’. Begin and End are called when the animation passes over the begin and end of the state notify and the Tick function is called once every frame that the animation remains inside the state notify.

Notifies do come with a noteworthy limitation when compared to normal blueprints in that they cannot store any instanced data within themselves. In practice this means you cannot set variables from within the notify, they can only be used to pass data into the notify. This is because the notifies belong to the animation sequence, and each skeletal mesh playing that sequence references the same object.

Native Animation Notifies

Blueprints aren’t the only way to handle notify events, they can be implemented natively in code as well. Simply create a new class derived from UAnimNotify or UAnimNotifyState either manually or using the class viewer. For an animation notify simply implement Received_Notify and for an animation notify state implement Received_NotifyBegin, Received_NotifyTick and Received_NotifyEnd. In Persona the native notifies will appear in their own section of the menu:

6.png

Just like a blueprint notify, native notifies can expose variables to be set in the details panel for the notify, although there is a bit of special syntax required; here’s an example notify class:


UCLASS()
class UAnimNotifyNativeTest : public UAnimNotify
{
    GENERATED_UCLASS_BODY()

    virtual bool Received_Notify(class USkeletalMeshComponent* MeshComp, class UAnimSequence* AnimSeq) const;

    UPROPERTY(EditAnywhere, Category = Parameters)
    float TestFloatParameter;
    UPROPERTY(EditAnywhere, Category = Parameters)
    UClass* TestClassParameter;
    UPROPERTY(EditAnywhere, Category = Parameters)
    TArray<int32> TestArrayParameter;
};


When exposing variable from code, ensure you have the ‘EditAnywhere’ metadata on the property macro line, along with a category to put the variables in on the details panel.

For more detailed documentation on blueprints and animation blueprints, check out the following documentation pages: Blueprints](Blueprint Visual Scripting | Unreal Engine Documentation) and Animation Blueprints](Animation Blueprints | Unreal Engine Documentation).

We hope this was helpful for you guys! As always, if you have any question or comments please post them below!

I have a custom event (melee apex of swing point in the animation) and a MeleeNotifyStateBP blueprint, and the Receive Notify Begin with a Print String and that works fine.

When the NPC does an arm swing at the player, at the apex of the swing it prints “Melee Notify Begin” to the console.

I want to take damage, do knockback, slow the player some (shock) and such.

Also our game is heavily C++ in the AI event area so in the end I need the event to go into the C++ code on the ANPCCharacter class.

If I get the event in the NPCCharacter blueprint, that is fine, I can do a call into the C++ ANPCCharacter code.

How do I get the event over to the NPC actor blueprint?

Later: (Face palm), as usual, after asking the answer becomes obvious. The mesh has a GetOwner that is the NPC Character Actor. You can cast it and call functions,