4.21.2014

Crash Course in Animation Notifies

By Benn Gallagher

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:

Creating a new animation notify

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:

Bluepritn variables in the blueprint editorThe animation details panel

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.

Event notify in a blueprint

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.

An Implemented notify state tick function

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:

adding a native anim notify

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 and Animation Blueprints.

We hope this was helpful for you guys! As always, if you have any question or comments don’t forget to head over to the forums and send us a note. 

Recent Posts

BMW Brings Mixed Reality to Automotive Design with Unreal Engine

The world of automotive design is changing rapidly, with real-time technolo...

Sumo Digital Discusses Shipping on Nintendo Switch

The studio that used Unreal Engine to bring Snake Pass to Switch speaks abo...

Join us for Unreal Academy: Enterprise

Unlock the power of Unreal Engine for Enterprise in our upcoming two-day tr...