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!
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](https://i0.wp.com/unreal-mmo-dev.com/wp-content/uploads/2024/06/image.png?resize=1024%2C496&ssl=1)
We will also use another plugin called ‘Chooser’ so find and enable that too.
![Enable Chooser plugin](https://i0.wp.com/unreal-mmo-dev.com/wp-content/uploads/2024/06/image-1.png?resize=1024%2C491&ssl=1)
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](https://i0.wp.com/unreal-mmo-dev.com/wp-content/uploads/2024/06/image-2.png?resize=884%2C234&ssl=1)
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](https://i0.wp.com/unreal-mmo-dev.com/wp-content/uploads/2024/06/image-13.png?resize=1024%2C497&ssl=1)
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](https://i0.wp.com/unreal-mmo-dev.com/wp-content/uploads/2024/06/image-14.png?resize=1024%2C549&ssl=1)
Select all the animation sequences here that you wish to import to your project.
![Migrate the assets to your project](https://i0.wp.com/unreal-mmo-dev.com/wp-content/uploads/2024/06/image-15.png?resize=814%2C543&ssl=1)
When you click Migrate, UE will automatically evaluate all dependencies and select them for you.
![Animation dependencies](https://i0.wp.com/unreal-mmo-dev.com/wp-content/uploads/2024/06/image-16.png?resize=613%2C545&ssl=1)
Select the Content folder of your project when migrating these assets.
![Select Content folder of your project for migration](https://i0.wp.com/unreal-mmo-dev.com/wp-content/uploads/2024/06/image-17.png?resize=769%2C282&ssl=1)
If you open up your project, you should now find those animations available.
![Animations available in your project](https://i0.wp.com/unreal-mmo-dev.com/wp-content/uploads/2024/06/image-18.png?resize=1024%2C404&ssl=1)
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.
![](https://i0.wp.com/unreal-mmo-dev.com/wp-content/uploads/2024/06/image-19.png?resize=458%2C457&ssl=1)
![Retarget animation menu](https://i0.wp.com/unreal-mmo-dev.com/wp-content/uploads/2024/06/image-20.png?resize=1024%2C603&ssl=1)
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](https://i0.wp.com/unreal-mmo-dev.com/wp-content/uploads/2024/06/image-22.png?resize=1100%2C155&ssl=1)
So now I am able to select it in the target.
![](https://i0.wp.com/unreal-mmo-dev.com/wp-content/uploads/2024/06/image-23.png?resize=1024%2C604&ssl=1)
Select all animations from the menu and click Export Animations.
![](https://i0.wp.com/unreal-mmo-dev.com/wp-content/uploads/2024/06/image-24.png?resize=1024%2C613&ssl=1)
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](https://i0.wp.com/unreal-mmo-dev.com/wp-content/uploads/2024/06/image-25.png?resize=1024%2C491&ssl=1)
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](https://i0.wp.com/unreal-mmo-dev.com/wp-content/uploads/2024/06/image-4.png?resize=1024%2C520&ssl=1)
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](https://i0.wp.com/unreal-mmo-dev.com/wp-content/uploads/2024/06/image-5.png?resize=739%2C492&ssl=1)
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](https://i0.wp.com/unreal-mmo-dev.com/wp-content/uploads/2024/06/image-8.png?resize=1024%2C497&ssl=1)
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](https://i0.wp.com/unreal-mmo-dev.com/wp-content/uploads/2024/06/image-26.png?resize=929%2C458&ssl=1)
With all the animations selected, right click -> asset actions -> edit selection in property matrix.
![](https://i0.wp.com/unreal-mmo-dev.com/wp-content/uploads/2024/06/image-27.png?resize=1024%2C548&ssl=1)
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.](https://i0.wp.com/unreal-mmo-dev.com/wp-content/uploads/2024/06/image-28.png?resize=1024%2C255&ssl=1)
It should then look like this:
![root motion enabled for animation sequences.](https://i0.wp.com/unreal-mmo-dev.com/wp-content/uploads/2024/06/image-29.png?resize=387%2C127&ssl=1)
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:
![](https://i0.wp.com/unreal-mmo-dev.com/wp-content/uploads/2024/06/image-30.png?resize=1024%2C400&ssl=1)
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.
![](https://i0.wp.com/unreal-mmo-dev.com/wp-content/uploads/2024/06/image-31.png?resize=1024%2C555&ssl=1)
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](https://i0.wp.com/unreal-mmo-dev.com/wp-content/uploads/2024/06/image-32.png?resize=379%2C427&ssl=1)
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](https://i0.wp.com/unreal-mmo-dev.com/wp-content/uploads/2024/06/image-33.png?resize=1024%2C268&ssl=1)
Now let’s go to the Anim Graph. For context, this is my BEFORE:
![Before motion matching in Anim Graph.](https://i0.wp.com/unreal-mmo-dev.com/wp-content/uploads/2024/06/image-34.png?resize=1024%2C455&ssl=1)
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:
![](https://i0.wp.com/unreal-mmo-dev.com/wp-content/uploads/2024/06/image-35.png?resize=917%2C547&ssl=1)
It’s now ready.
![Motion Matching connected](https://i0.wp.com/unreal-mmo-dev.com/wp-content/uploads/2024/06/image-36.png?resize=1024%2C452&ssl=1)
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](https://i0.wp.com/unreal-mmo-dev.com/wp-content/uploads/2024/06/image-38.png?resize=1024%2C443&ssl=1)
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](https://i0.wp.com/unreal-mmo-dev.com/wp-content/uploads/2024/06/image-40.png?resize=1024%2C615&ssl=1)
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](https://i0.wp.com/unreal-mmo-dev.com/wp-content/uploads/2024/06/image-41.png?resize=1024%2C257&ssl=1)
Next, let’s create another database (PSD) for the jump motions.
![Create PSD for jump motions](https://i0.wp.com/unreal-mmo-dev.com/wp-content/uploads/2024/06/image-42.png?resize=315%2C176&ssl=1)
Let’s add all the jump animations to it.
![Add jump animations to PSD](https://i0.wp.com/unreal-mmo-dev.com/wp-content/uploads/2024/06/image-43.png?resize=1024%2C782&ssl=1)
Configure Chooser to use the new PSD
Right click in content browser and search Chooser and create this table.
![Create Chooser table](https://i0.wp.com/unreal-mmo-dev.com/wp-content/uploads/2024/06/image-44.png?resize=650%2C582&ssl=1)
When you created your chooser table, you will want to configure it.
![Configure your chooser table](https://i0.wp.com/unreal-mmo-dev.com/wp-content/uploads/2024/06/image-45.png?resize=616%2C515&ssl=1)
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](https://i0.wp.com/unreal-mmo-dev.com/wp-content/uploads/2024/06/image-46.png?resize=474%2C250&ssl=1)
Insert the two options for the PSD that we have, these are the potential outputs.
![Select two PSD for motion matching](https://i0.wp.com/unreal-mmo-dev.com/wp-content/uploads/2024/06/image-47.png?resize=511%2C549&ssl=1)
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](https://i0.wp.com/unreal-mmo-dev.com/wp-content/uploads/2024/06/image-49.png?resize=719%2C420&ssl=1)
I can now bind the bool to the isInAir from animation blueprint, as that was configured on the input value.
![bind boolean to isInAir](https://i0.wp.com/unreal-mmo-dev.com/wp-content/uploads/2024/06/image-50.png?resize=727%2C277&ssl=1)
Finally, the result should look like this:
![Completed basic chooser table.](https://i0.wp.com/unreal-mmo-dev.com/wp-content/uploads/2024/06/image-51.png?resize=681%2C199&ssl=1)
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.
![](https://i0.wp.com/unreal-mmo-dev.com/wp-content/uploads/2024/06/image-52.png?resize=1024%2C270&ssl=1)
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](https://i0.wp.com/unreal-mmo-dev.com/wp-content/uploads/2024/06/image-53.png?resize=1024%2C489&ssl=1)
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](https://i0.wp.com/unreal-mmo-dev.com/wp-content/uploads/2024/06/image-54.png?resize=1005%2C387&ssl=1)
Next, create a binding on update.
![create on-update binding for motion matching](https://i0.wp.com/unreal-mmo-dev.com/wp-content/uploads/2024/06/image-55.png?resize=1024%2C303&ssl=1)
Inside this binding, we configure the chooser to select the database.
![configure chooser to select the database](https://i0.wp.com/unreal-mmo-dev.com/wp-content/uploads/2024/06/image-56.png?resize=1024%2C312&ssl=1)
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](https://i0.wp.com/unreal-mmo-dev.com/wp-content/uploads/2024/06/image-57.png?resize=1100%2C517&ssl=1)
For the bone, I’ve selected Pelvis, which is the parent/root of the Spine.
![Select pelvis as bone](https://i0.wp.com/unreal-mmo-dev.com/wp-content/uploads/2024/06/image-58.png?resize=1024%2C120&ssl=1)
Now add another channel and this time select Position, select Pelvis for the bone again.
![Create position channel.](https://i0.wp.com/unreal-mmo-dev.com/wp-content/uploads/2024/06/image-59.png?resize=1024%2C121&ssl=1)
This should now work smoother
![motion matching working on jump](https://i0.wp.com/unreal-mmo-dev.com/wp-content/uploads/2024/06/image-60.png?resize=733%2C410&ssl=1)
![Motion matching working with character](https://i0.wp.com/unreal-mmo-dev.com/wp-content/uploads/2024/06/motionMatching.jpg?resize=1024%2C621&ssl=1)