Devlog 58: How to add the new Motion Matching to our UE5 project

motion matching with Unreal Engine
UE 5.4 motion matching

We’ve previously looked at how to create a simple animation blueprint for actors in our project.

In this post, we will look at how to leverage the new motion matching feature that’s released with Unreal Engine 5.4.

The official documentation can be found here: Motion Matching In Unreal Engine | Unreal Engine 5.4 Documentation | Epic Developer Community (epicgames.com)

It’s quite good, so do check it out!

Motion Matching integration

Pre-requisites for Motion Matching

First, you need to make sure you have Unreal Engine 5.4+ installed, I am using 5.4.1.

Next, you will need to enable the Motion Matching plugin in your project, its named ‘Motion Trajectory‘. Find the plugins menu by clicking Edit -> Plugins.

Enable Motion Trajectory plugin

We will also use another plugin called ‘Chooser’ so find and enable that too.

Enable Chooser plugin

Next, get yourself the actor class you want along with the animations. A lot of people choose to use Lyra animation set.

I will personally be testing with assets from N-Hance studios.

So you mainly need a character blueprint, something like this:

character blueprint

Default UE Mannequin will work.

And a set of animation sequences that you want to integrate with motion matching. For animations, I will integrate with ones from Lyra project.

Getting animations from Lyra project

So you can find a lot of different animations on the UE marketplace. In this particular step, we will integrate the Lyra default/unarmed animations.

First, find the Lyra starter project in UE marketplace:

Lyra starter project

When you create the project, we can search and find the unarmed animations in: content -> characters -> heroes -> mannequin -> animations -> locomotion -> unarmed.

Ideally they’d be split into different categories and organized in their directories. Will get into that when we start putting them together.

Lyra unarmed animations

Select all the animation sequences here that you wish to import to your project.

Migrate the assets to your project

When you click Migrate, UE will automatically evaluate all dependencies and select them for you.

Animation dependencies

Select the Content folder of your project when migrating these assets.

Select Content folder of your project for migration

If you open up your project, you should now find those animations available.

Animations available in your project

Retarget animations

I will assume that your game is not planning to use the mannequin, like mine. So you will also need to retarget these animations.

In order to retarget, right click an animation and select Retarget Animations.

Retarget animation menu

Here you will need to select the target skeletal mesh.

Your assets should have existing skeleton/skeleton mesh blueprints or animation blueprints.

I am able to confirm the desired skeleton mesh blueprint to use from my packs animation sequence examples, like so:

Checking skeletal mesh to use from animation sequence

So now I am able to select it in the target.

Select all animations from the menu and click Export Animations.

The assets I use are compatible with the UE skeleton, so the auto retarget functionality works well. You should check that your skeleton is compatible, otherwise you may need to do additional steps to get this working properly.

After this export, you should now have the animations available and ready to use.

Retargeted animations ready to use

Creating motion matching for your character

Now you’re ready to start configuring the motion matching for your character.

First, create the motion matching Pose Search Schema. You can find it by right clicking, under animation -> motion matching. If you don’t see it, it means you haven’t enabled the plugin so check the pre-requisite step.

Create Post Search Schema for motion matching

The motion matching is applied based on skeleton, so find the skeleton which is used in your character blueprint.

Set the skeleton used by actor BP

I called this file ‘Hu_M_PSS’ and I will have a different one for each different skeleton character that I have. For example:

  • human male
  • human female
  • orc male
  • orc female

Next, we want to create the Pose Search Database:

Create Pose Search Database for motion matching

Link it to the previously created PSS, I named this file Hu_M_PSD_Default as it will be the pose search database for human male and it will be for default movement set. I.e. when the character is not equipping special weapons, not swimming/floating/combat etc.

Preparing animations

First thing we want to do is enable root motion on all the animation sequence assets you will be using.

Note that not all animation sequence assets have this feature available. For example, the animations with N-Hance assets do not support root motion at the time of writing this post. I have raised this as a bug/feature request with their team but can expect it will take months to resolve.

I will first search all animation sequence blueprints in the sub-folder:

searching animation sequence blueprints

With all the animations selected, right click -> asset actions -> edit selection in property matrix.

In this menu, select all animations and make sure to get a tick on enable root motion and Force root Lock.

enable root motion and force root lock.

It should then look like this:

root motion enabled for animation sequences.

Organizing animation sequences

Now I want to organize the animations I will be using in motion matching. I want to find all the default animations that I want to use. By this I mean ones which are not dependent on factors other than basic motion.

Other factors include things like:

  • falling/floating
  • combat
  • swimming
  • equipped weapons (2h, bow, etc)

I go ahead and copy or move animation sets into a new sub-folder for my default animations:

As you can see, it includes animations for:

  • walking
  • running
  • idle
  • jump

All the animations are for either no weapons equipped and they’re also suitable for 1h weapons too.

Add animations to database

Now we can open the PSD and start adding these animations.

Simple way to do that is to open the content browser that you should see at bottom left when your PSD is open. Then simply find the animations and drag them in.

Feel free to add just the ones you require to this database of animations.

In this one, I included:

  • idle
  • walk
  • run

For jump, we will cover that separately through another database – we will cover that further in this post.

Now we want to start linking these to our character, we do this through animation blueprints.

Before we do that, we also need to add Character Trajectory component to our actors.

Add character trajectory component to character

Animation Blueprints

Inside your Animation Blueprint, find the Event graph and in event begin play, we want to get the Character Trajectory component and promote it to a variable.

Get Character trajectory and promote to variable

Now let’s go to the Anim Graph. For context, this is my BEFORE:

Before motion matching in Anim Graph.

You will want to add Motion Matching (under pose search) and then connect it to Pose History function.

Link the trajectory using binding, like this:

It’s now ready.

Motion Matching connected

Testing the animations

When I tried to play game, I got some compile errors from Footstep Effect Tag Modifier:

Errors in footstep effect tag modifier

For the time being, I will simply disconnect this function and will check fixing it in future.

After disconnecting, I have the basic motion matching working, as expected.

Running works as expected

This motion matching is able to handle

  • idle
  • walk
  • run

all for unarmed/default motion (non-crouching, etc.)

How do we add other motion matching pieces

Now we will want to extend the functionality of motion matching by allowing us to switch the databases used for motion matching.

This can be achieved using the new Chooser plugin.

Chooser plugin

Next, let’s create another database (PSD) for the jump motions.

Create PSD for jump motions

Let’s add all the jump animations to it.

Add jump animations to PSD

Configure Chooser to use the new PSD

Right click in content browser and search Chooser and create this table.

Create Chooser table

When you created your chooser table, you will want to configure it.

Configure your chooser table

It will be used in your Animation Blueprint so select the context data as the animation blueprint used by the actors/character.

The output is the Pose Search Database so select that.

Now you can Add Row and select Asset.

Select asset for new row

Insert the two options for the PSD that we have, these are the potential outputs.

Select two PSD for motion matching

Now you want to add another column, which is used to determine which PSD is used.

This can be whatever you need it to be, for Jumping, it should be boolean – more accurately, it’s ‘isFalling’.

Add bool column

I can now bind the bool to the isInAir from animation blueprint, as that was configured on the input value.

bind boolean to isInAir

Finally, the result should look like this:

Completed basic chooser table.

Adding parameters in your animation blueprint

Just in case you’re not sure how to add and link the variables in your animation blueprint.

These are simple variables that are in your animation blueprint, which are configured in your event graph.

Here is an example of how the IsInAir set, which is taken from the movement component.

Connect the Chooser table in Animation Blueprint

Let’s go back now to where we have the motion matching configured in our Animation Blueprint.

We should have the following:

Motion matching in anim blueprint

Now select the Motion Matching node and change the Database connection to be Dynamic Value, also un-expose it as pin.

Change motion matching database to be dynamic value

Next, create a binding on update.

create on-update binding for motion matching

Inside this binding, we configure the chooser to select the database.

configure chooser to select the database

Adding another channel to PSS

This should now work but not too well.

We want to add another two channels for the PSS to monitor, so open that up and find the ‘channels’ settings and add new field, for Velocity Channel.

Add velocity channel to PSS

For the bone, I’ve selected Pelvis, which is the parent/root of the Spine.

Select pelvis as bone

Now add another channel and this time select Position, select Pelvis for the bone again.

Create position channel.

This should now work smoother

motion matching working on jump
Motion matching working with character