Tag

example

Unreal Engine C++ Fundamentals – UAnimNotify & UAnimNotifyState

By | Development, Tutorial, Unreal | No Comments

Hey guys,
Today we are going to continue exploring Unreal Engine C++ Fundamtals to slowly get back to our Player Character series by taking a look at Anim Notify and Anim Notify States.

You can find the GitHub project for this video in the usual location.

What is a Anim Notify ?

An Anim Notification or a UAnimNotifyis a way of assigning events to parts of our animation that will be triggered at specific times of the animation playback.
UAnimNotifiesreally only have one notification event. It either fires or it doesn’t.

 

Why do I care ?

Well most games have various animations and each animation may trigger different effects depending on it’s life cycle.
For example if we want to play back a noise that a weapon makes as our character slices it through the air we may want to use an UAnimNotifyto trigger this event and then we can tie that event to the playback of our wooooshing sound.
We can also use notification events to trigger special effects, events in the game, UI updates, whatever you can imagine you can tie into this execution.

Ok smart guy what about Anim Notify States ?

Anim Notify States or UAnimNotifyStateare almost identical to our Anim Notifies except for one difference and that is that Anim Notify States come with three events:

  • NotifyBegin
    • This even is fired once when the notification is first triggered.
  • NotifyTick
    • This event fires continuously every tick, during the execution of an UAnimNotifyState.
  • NotifyEnd
    • This even fires once at the end of the UAnimNotifyStateexecution.

 

Alright so we have these magical events, how do we code them ?

First let’s take a look at a UAnimNotify

// HEADER

UCLASS()
class UE4FUNDAMENTALS03_API UPunchThrowAnimNotify : public UAnimNotify
{
  GENERATED_BODY()

public:
  virtual void Notify(USkeletalMeshComponent* MeshComp, UAnimSequenceBase* Animation) override;

};


// SOURCE CPP

void UPunchThrowAnimNotify::Notify(USkeletalMeshComponent* MeshComp, UAnimSequenceBase* Animation)
{
    // print method name to screen
    GEngine->AddOnScreenDebugMessage(-1, 4.5f, FColor::Purple, __FUNCTION__);
}

So as you can see by inheriting from UAnimNotifywe are able to overwrite the “Notify” method and then print some stuff to the screen.
Pretty easy.

Now let’s see what a UAnimNotifyStatelooks like

// HEADER H

UCLASS()
class UE4FUNDAMENTALS03_API UPunchThrowAnimNotifyState : public UAnimNotifyState
{
  GENERATED_BODY()

public:
  virtual void NotifyBegin(USkeletalMeshComponent* MeshComp, UAnimSequenceBase* Animation, float TotalDuration) override;
  virtual void NotifyTick(USkeletalMeshComponent* MeshComp, UAnimSequenceBase* Animation, float FrameDeltaTime) override;
  virtual void NotifyEnd(USkeletalMeshComponent* MeshComp, UAnimSequenceBase* Animation) override;
  
};


// SOURCE CPP

void UPunchThrowAnimNotifyState::NotifyBegin(USkeletalMeshComponent* MeshComp, UAnimSequenceBase* Animation, float TotalDuration)
{
    GEngine->AddOnScreenDebugMessage(-1, 4.5f, FColor::Yellow, __FUNCTION__);
}

void UPunchThrowAnimNotifyState::NotifyTick(USkeletalMeshComponent* MeshComp, UAnimSequenceBase* Animation, float FrameDeltaTime)
{
    GEngine->AddOnScreenDebugMessage(-1, 4.5f, FColor::Yellow, __FUNCTION__);
}

void UPunchThrowAnimNotifyState::NotifyEnd(USkeletalMeshComponent* MeshComp, UAnimSequenceBase* Animation)
{
    GEngine->AddOnScreenDebugMessage(-1, 4.5f, FColor::Yellow, __FUNCTION__);
}

Cool ! Now show me how to tie those events into my game.

Well the majority of that is covered in the video but if you are curious this is what the events look like when you add them to the animations.

The way we added in these notifications is by going to the bottom part of the animation montage labeled “Notifications”.
Then by Right Clicking we were able to pick our notifications.

This was all done from the Melee animation montage.

 

POINT OF NOTE:

UAnimNotifyand UAnimNotifyStatescan be added to single animations as well as animation montages. Which gives you a lot of free demo as to where and how you want these events to be triggered.

 

So there we go guys, with just a few lines of code and a bit of clicking we have notifications coming out of our animations and into our game.
If you would like to learn a little bit more about these various topics, check out the following links:

Unreal C++ Tutorial – Player Character Series – Punch – Part 2 – Collisions

By | Development, Tutorial, Unreal | No Comments

Hey guys,

Today we are going to pick up where we left off last time with our Player Character and we are going to introduce collisions.

Now to get our collisions working we are going to jump into a few topics like:

  • Mesh Sockets – 1:45 – these sockets will allow us to attach our Box Components to parts of our fists during the firing of our animations
  • Box Components – 6:25 – these small collision boxes will allow us to apply specific collision profiles at run-time in order to trigger the interaction with our target
  • Animation Notify States – 31:15 – these are notifications that will fire during the course of our animation playback and trigger specific events on our player character. In our case we are simply going to enable the collisions on our collision boxes.

As usual we have our starter project on GitHub as well as the final version for you to try out. Additionally here are a few links to do some further reading on the items we discussed.

Thanks for taking a lookt and tune back for more.

Animation Re-targeting with Unreal using Mixamo assets

By | Development, Tutorial | No Comments

Hey guys,

Today I have another tutorial for you, this time discussing how you can import new animations into Unreal Engine and re target them against your character.

For my example I will be using a character from Mixamo, which is a site support by Adobe that has various 3d models and animation resources for folks to use. Since the animations come with their own skeletal definitions you have to re target them otherwise they will be unusable when you bring them into Unreal.

You can also find the source code used in this tutorial on my GitHub page.

In addition to the video here is a quick map of the bones from the Unreal Mannequin and how they map against the Mixamo model.

Also a few more resources from Epic about animation re targeting.

Thanks for taking a look and stay tuned for more.

Unreal – Base

Mixamo

Root Hips
Pelvis Hips
spine_01 Spine
spine_02 Spine1
spine_03 Spine2
clavicle_l LeftShoulder
UpperArm_L LeftArm
lowerarm_l LeftForeArm
Hand_L LeftHand
clavicle_r RightShoulder
UpperArm_R RightArm
lowerarm_r RightForeArm
Hand_R RightHand
neck_01 Neck
Head head
Thigh_L LeftUpLeg
calf_l LeftLeg
Foot_L LeftFoot
Thigh_R RightUpLeg
calf_r RightLeg
Foot_R RightFoot

Unreal – Advanced

Mixamo

index_01_l LeftHandIndex1
index_02_l LeftHandIndex2
index_03_l LeftHandIndex3
middle_01_l LeftHandMiddle1
middle_02_l LeftHandMiddle2
middle_03_l LeftHandMiddle3
pinky_01_l LeftHandPinky1
pinky_02_l LeftHandPinky2
pinky_03_l LeftHandPinky3
ring_01_l LeftHandRing1
ring_02_l LeftHandRing2
ring_03_l LeftHandRing3
thumb_01_l LeftHandThumb1
thumb_02_l LeftHandThumb2
thumb_03_l LeftHandThumb3
lowerarm_twist_01_l
upperarm_twist_01_l
index_01_r RightHandIndex1
index_02_r RightHandIndex2
index_03_r RightHandIndex3
middle_01_r RightHandMiddle1
middle_02_r RightHandMiddle2
middle_03_r RightHandMiddle3
pinky_01_r RightHandPinky1
pinky_02_r RightHandPinky2
pinky_03_r RightHandPinky3
ring_01_r RightHandRing1
ring_02_r RightHandRing2
ring_03_r RightHandRing3
thumb_01_r RightHandThumb1
thumb_02_r RightHandThumb2
thumb_03_r RightHandThumb3
lowerarm_twist_01_r
upperarm_twist_01_r
calf_twist_01_l
ball_l LeftToeBase
thigh_twist_01_l
calf_twist_01_r
ball_r RightToeBase
thigh_twist_01_r
ik_foot_root
ik_foot_l
ik_foot_r
ik_hand_root
ik_hand_gun
ik_hand_l
ik_hand_r
Custom_1
Custom_2
Custom_3
Custom_4
Custom_5