How to Add Motion Matching to Metahumans in Unreal Engine 5.4 : Beginner Guide

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hello everyone in this video I will show you how to do motion matching for metahumans to begin with we're going to create a third person project in Unreal Engine 5.4 so you can call it whatever you want you do not need starter content or R tracing for this project right so once you're in your project uh in your third person template we do need some new plugins so we're going to go to edit and we're going to go to plugins here and there's two plugins you need to add for motion matching one of them is called post search so you can look for that enable it um it's going to ask you to restart but we're going to wait until we activate the other one which is called trajectory so motion trajectory you can see it's an experimental uh but that's okay so you're going to hit that it's going to say are you sure you want to enable the plugin even though it's an experimental um I'm going to click yes here and then um I'm going to not restart yet what I want to do here is I I want to also add my metahuman so you can go into add go into a quickel content and you can add whatever metahuman you want for your project I'm going to go to my meta humans right here and I have two pre-downloaded ones and I'm going to choose one of them here so I'm going to choose Christopher this time for a change of scenery and once you have downloaded it you'll have to first download um your icon is going to be like this but once it's downloaded you can add it to your project now once your metahuman is added to your project you can you can see the folder here you may want to open the blueprint and the Unreal Engine will tell you if your the plugins for um the metahumans are missing and you want to enable them so you can go ahead and enable all of the different plugins okay so as you can see it opened my metahuman here um I can go ahead and put it in my main window if you want it to always go to your main window you can go to edit editor preferences and over here under General appearance if you scroll all the way down there is a um asset editor open location so as you can see it's in default right now and you can make it change to um always open in the main window and you can go ahead and close that so with that done uh our base project is almost ready we just need animations for metahuman so we're going to go ahead and close our project all right the next step is you want to go to um the Epic Launcher and you want to go into Marketplace and you want to search for the L project the L project has a bunch of animations that we can use for motion matching um they are going to release um did they they did say they're going to release an animation pack for the mannequin at some point but um doesn't look like it's here yet so we can just use the L project project so as you can see I've already downloaded it but if you haven't you can just click on it and you can hit create project and it'll create a project from the L project once you do that you can actually just open the project all right so as you can see we're in the L project right now uh and the whole reason we're actually using the L project is just because we want the animations so I just wanted to show you a neat trick so we're we're looking for the animations here and we don't know exactly which folder they're in so we can just click on cont and we can use this filter icon here and we want to tell it that we want to actually look for animation sequences so if we click on it like here um it'll show us all the animation sequences and if we hover over them it'll tell us where the loation the location is and as you can see it's under man um this one this specific one is under Manu but the ones that we're specifically looking for are the um the ones specific to lra which is these ones right here and you can see they're under Heroes mannequin animations Locomotion so it's just a neat trick you can use here so we're going to go into characters and we're going to remove the filter for one second and we're going to Heroes mannequin and animations and what we really care about right now is just the local motion animations so just the movements and for the movements they have a bunch of different ones ones with the rifle pistol in hand and shotgun for now just since I want to show you how basics of Lo um motion matching work we're just going to go with the unarmed movement and we don't really need the animation blueprints or anything like that we really care about just the animation sequences so again we're going to use this filter and uh I really I mainly want to do a the male uh mannequin right now so um depending on what you want to do you can make a decision so I'm going to just grab all the animations with the m mm in front of it so it starts from here and I'm going grab it all the way to here you could also grab all of them if you want so once you choose all of them uh I did I did so by clicking shift clicking um you can right click and go into asset actions and there's an option to migrate and what migrate does is it moves a bunch of assets from one project to another so we're going to hit migrate here and it's going to choose all the different um files associated with the animations some of them we really don't need um at all but I'm not going to go into details of which ones to exclude and include you can just include everything for now because I don't want to waste your guys time so once you hit migrate you're going to have to choose the where you want to migrate to so you're going to go into your metahuman project that you created and you need to make sure you choose the content folder for your project that's just a requirement and you're going to hit select folder and it'll migrate everything for you so once that is done the all the animations are moved to your new project project you can go ahead and close your Leo project and open up the metahuman project again all right we're back inside our metahuman project and we can see that um under our charact under our content folder there's now a characters folder and on underneath you'll see all the different um animations that we migrated over so I'm going to remove this filter for now and now that we have the animations we can go ahead and start with the motion matching so so the first thing we need to do is we need to migrate all of the animations from the mannequin to the metahuman I did show you this how to how to do this in another video but we're going to go ahead and do it again here but I'm not going to explain as much so I'm going to go into Locomotion unarmed and I'm going to filter by animation uh animation sequence and I'm going to go ahead and choose everything I'm going to hit control a here and it's going to choose all the animations here and I'm going to right click go to migrate Target animations and it's going to open a new window where we can actually retarget our animation The Source skeletal mesh is skm many and the target skeletal mesh uh in my case is the medium male so it's this one right here Med medium uh normal weight body so I'm going to go ahead and choose this and I'll show you how you can figure this out in a second of what your what the skeleton of your um metahuman is but once you choose that you can actually choose the anim animations you want to retarget so as we said before we want to Target the mm uh animations that were from lero so I'm going to choose all of them right here and I'm going to hit export animations I'm going to go into my metahuman folder go under Christopher and I'm going to create a new folder here and I'm going to call it animations just to keep things neat and I'm going to choose this folder here and I'm going to hit export and I'm going to hit export again and just like that uh UE 5.4 retargets all your animations for you which is quite neat now I did tell you I want to show you how you can find out what the skeleton of your metahuman is so if you go into your metahuman folder and you open your the blueprint for your metahuman if you click on the body and you scroll down under um mesh you'll see your skeletal mesh asset and here you'll see the name of the um skeletal mesh for your metahuman all right so once you do that you are ready to actually get started so we're going to right click here in the metahuman uh main folder you don't have to do it here uh so it's just something I'm doing I'm going to hit right click go into animations and you should see the motion match motion matching option here um if you're not seeing it uh look at the start of the video you need to make sure you're enabling the plugins so the first thing you need to create is a post search schema and it's going to ask you for the skeleton you can choose the Met met human base skeleton here this is the base skeleton for all metahumans so you're going to choose that and you can name it whatever you want so I'm going to call it PSS short for post search schema and I'm going to put MH for metahuman um you don't need to actually do any changes for this um this has a few options I haven't really looked into what exactly um they do and everything like that but perhaps in a future video but for now we need to create a the schema because it's required for the next step so the next step is to create a database of animations that our um motion matching is going to use so we're going to go into animation and then again motion matching and then choose the post search database and you'll see as soon as you hit post search database it asks for a schema that's why we had to create it in the previous slip so we're going to choose that and we have to call this uh again so post search database so it's PSD and again we are going to name it U PSD Christopher okay so once that's this is one of the main assets that we need to take care of this is all the different animations that the motion matching algorithm is going to use um and the way it works is that um it kind of um estimates the trajectory of a character's movement and based on how the character is moving and in which direction the character is moving uh it chooses an animation that's in the state of datase so we need to put all the different animations we want to take care of here right so now we need to add the animations we need for PSD Christopher and one quick thing I do want to show you is if you scroll down in the database details you can see the preview mesh and you can choose the preview mesh that you want for your animations so you can make sure that you choose the body preview of whatever um skeleton you're using for your metahuman so I'm going to choose my the body preview for my metahuman and then I'm going to open my content drawer and I'm going to add I want to make sure you want to make sure that when you're choosing your animation you go on under metahumans uh go to where you actually saved your retargeted animations it's very important and in our case um I want the jog animations and idle animations so I'm going to search for Jog and I'm going to choose all the different animations I have for jogs and I'm going to put it here and if you've done it correctly if you click on one of the animations it'll show the metahuman jogging so I can choose all of them actually and you can see the chaos that un rails and the other animation I do make sure I want to add is the idle animation so I'm going to go here and I'm going to add one of the idle animations I don't want all of them because I don't want it to juggle between all the different ones uh because the way it works is it chooses an animation based on how your character is moving so once you do that you hit save and you can move along and now what we want to do is we want to actually add our meta human into the world and be able to move it and have the motion matching work for it so the first step in order to do that is we need to replace the third person uh the BP third person template when we hit play right uh we can ignore this for now I'll show you how to fix this in a second but when we hit player right now we have the mannequin as the main player so the first thing we need to do is change that um so we're going to open the BP Christopher and we're going to also go into uh we're going to close everything down open content and go into third person Blueprints and BP third person and we're going to duplicate this and we're going to call this MH character and it's a good idea to always duplicate so in case you mess something up you still have the main one which you can use as reference so we're going to open BP MH character and we want to have our metahuman here so as you can see the metahuman uh structure is a bit different than the third person template so I'm going to bring it all the way here so I can show you guys this so in the metahuman we don't just have one skeletal mesh right we have the body feet legs torso and face and the face comes with a bunch of other stuff and also an LOD synchronizer so the first thing we're going to do is we're going to copy the LOD sync and we're going to bring it here and we're going to copy and paste it under this and it's going to add it here now a cool thing uh I've seen people ask around about metahumans is that they don't like it when the uh the beard disappears and the beard and the hair details and the way you can fix that is in the LOD sync you can force it to show it so this makes it so that depending on the distance uh it shows or it doesn't show the amount of detail but if you change it to one for example then you won't have that issue so you can see the bird the beard is still there when I move it back and forth right so the next step we want to do is we want to copy everything here under the body into the uh MH character so you're going to have to choose all of them you can't just choose the top part uh you have to choose everything here and you're going to hit copy under metahuman character we can stick it under the capsule component and you should have all your the all the now you have two skeletal meshes you have the main mesh here and the skeletal mesh and you may want to say oh can we just delete this but it's part of the character class so you can't really delete that one I'll show you how to work around that in a second so I'm going to rename this skeletal mesh to body just like it is in the metum and then what we want to do here is we want to make sure that the the metahuman is in the same direction as the third person so this step is important that we uh look at the character here and we look at its transform and we can see it's in minus 89 and 270 so you want to have the same exact attributes here and the reason for that is that the whole movement uh that is coded for the third person template is based on the character being oriented in this way so if you make this negative 90 instead of 270 it won't work I just wanted to um make sure that you understand that because it changes the axis the way if you if you um rotate it clockwise or counterclock wise so once you do that and you have everything set up you can move the body under the mesh so you can click drag it under the actual mesh here and then you can choose the mesh here and um we don't want to have the skeletal mesh showing so we're going to click on this and hit clear and we're going to also remove this animation blueprint and we're going to hit none here so now we're going to hit compile and save and once you do that if you hit um um we want to change the main player from BP third person to this blueprint that we created so if we hit on this game mode here BP third person game mode we can change the main Pawn so default Pawn class from BP third person character to our metahuman character so this step has nothing to do really with um motion matching but I know this is difficult for a lot of people to do so I kind of wanted to show it so if I hit play right now I should see my metahuman character and and I should be able to move it around and jump and everything like that so right now we have no animations of course but that's the whole point we're going to try to fix that with motion matching all right so now that we're set up we're going to close this blueprint Christopher we don't need it anymore we're going to close our game mode we don't need that anymore so we just need our metahuman character so we need we need a way to tell the database that our character is moving and in which direction it's moving so in order to do that you need to hit on ADD and there's a motion there's a trajectory character trajectory if you don't see this that means you didn't enable the plug-in um motion trajectory plugin that we did at the start so we hit that we added we don't really need to change the name so now that's added we can actually use this to tell the database uh which way our character is moving the way we do that is through a animation blueprint so let's get to do let's do that stuff so we're going to go into our metahumans folder and you don't have to put it here but this is what I'm going to be doing and I'm going to right click go to animation and I'm going to create an animation blueprint and it's going to ask for the base skeleton again you can choose the metahuman base skeleton here and you're going to hit create and I'm going to call it ABP Christopher and we're going to go ahead and open this and now right now you can see we're not doing anything and we want to use motion matching so previously when you wanted to do animations you had to create a state machine was pretty involved if you wanted to do all the different movements and everything like that uh but now we're going to use motion matching and in order to do motion matching we need two nodes one is called the motion matching node no surprise what this node does is it just takes in the database for the animations and we created one right so PSD Christopher is the database but we also need to let it know which way are character is moving what is the emotion trajectory for our character and in order to do that we actually search for Post history and you'll see it under post search so you're going to choose Post history and you can see the post history takes in a trajectory and then it takes it it takes in a pose a trajectory and it results in another pose so we're going to um drag in drop into the output pose and we're going to drag this one into the database so it's going to say so what these two are doing is saying it take the trajectory and and the database and see which animation you need to play and then play that animation so right now if I hit compile um nothing much happens because the character doesn't know what the trajectory is so we need to fix that one so in order to get the project TR the trajectory of the character we need to go into the event graph here of the animation blueprint and what we need to do is essentially we need to grab this character grab its character trajectory and feed it into the uh node that we created and we need to do that every frame right because the character is moving all the time so we're not doing this once we need we need this to happen every frame so in order to do that we use an event here and I'm going to show you so we need to First grab our character and the way you do that is search for event initialize so as as soon as our animation is initialized we want to grab our character and so here's here's how you grab your character unreal on already gives you this node but we want it to be the blueprint MH character and the way you do that is you can do cast BP MH character or whatever you named your blueprint so we do that and we make it a variable so we can always access it so we grab it and we say promote to variable and you can give it whatever name you want I'm just going to make it MH character okay so once we do that we can come inside here and what did we want to do we wanted every frame we wanted to grab the um trajectory of the character so the way we do that is we grab the variable that we just created so we grab our character and what you can do is you can right click on it and make this a validated get what this does is it makes sure that this this um this character exists in our world before it tries to access it right because it takes a when you hit play it takes a a little bit of time for it to actually get created into the world and since this is so fast and it's happening every frame it may be that this character is not created yet so what this does is make sure that that character is created so what we want to do here is we want to get the trajectory and what this does is it grabs the trajectory that we created here and you can see this trajectory in the details there's a bunch of different stuff that it has but what we really care about is just the trajectory at this point so what we want to do here is we want to say I want the actual trajectory I don't want anything else and once we do that we can promote this to a variable that we can use in the um because we want to save it right wherever the character is moving we want to know exactly at each point so I'm going to call this MH trajectory and we're going to set that so every frame we're going to grab the trajectory and we're going to set it here so I'm going to hit compile and save and then if we go back to our anim graph right here so instead of the pose we don't have anything here we can just grab our metahuman trajectory put it here and let me see if I can grab it yep there we go so now if I hit compile so as you can see right now we plugged in the trajectory the motion match and the post history and right now we can see our character's animation is in idle State because well our character is not moving so once we do that we hit save and now our animation blueprint is ready so now we are almost done so if you go into your BP image character you can now set the animation blueprint for the body here and it's going to ask use animation blueprint and we're going to choose our AB Christopher which is the one I just created so if this happens for you where your um body is in using an animation and your clothes are not uh what you want to do is choose your torso legs and feet and also choose the animation blueprint AB Christopher or whatever you called yours and that should fix it all right so we're going to hit compile we're going to hit save and now we're going to hit play and you can see our character is in well is in idle State and now I can move forward and it's the Running Animation I can run backwards right left and what I can do is um in order for it to do this drave animations we need to not have it not turn towards the the way it's moving so the way you can do that is and we'll fix this errors in a second the way you can do that is you can go into your BP main character and go into character movement and go ahead and search for Orient rotation to movement and you can disable that and hit compile and save and then you play this time when you move right you'll see it do the strafe right animation jog left jog right forward and backwards you can also jump and it does a short jump animation but you can change the amount you jump as well so it the animation plays better and I also didn't add the jump animations into the database but you can all you can add all of those if you want now let's go ahead and fix this error and let's I wanted to show you this so you can get an idea of why we use a validated git so right now it's saying that whenever it's trying to access the image trajectory variable um it's not set yet it's null so that's why we use the validated git so if we go back into animation blueprint go into the event graph it's saying that it doesn't know if this is um valid or not so what we can do here is we can do a validated G and only if if the character trajectory is set is when we want to um set the variable so if we hit compile here and hit save and we do that again and we hit Escape we won't get that error anymore and just like that you have your metahuman using motion matching you can go ahead and add jumping animations if you want as well and also running diagonally but pretty cool huh all right thanks for watching if you have any questions uh feel free to put it in the comments peace
Info
Channel: SipAndCode
Views: 1,363
Rating: undefined out of 5
Keywords: Sip&Code, SipAndCode, Motion Matching for Metahumans, Metahumans, Unreal Engine 5, Unreal Engine 5.4
Id: CM9z6aL8tek
Channel Id: undefined
Length: 25min 39sec (1539 seconds)
Published: Mon Apr 29 2024
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.