UE5 - Game Animation Sample: How to Add Overlay States

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
how's up guys so today we're going to be looking into the game animation sample and I'm going to teach you how to add some simple overlays so that we can have different weapons and different animations okay so um I think the project is nice um it could be a little bit better if these problems weren't here uh but I hope it gets fixed when the f ik is implemented so let's begin the first thing we need is uh an animation to serve uh as our overlay so let's go to characters uh ufan mannequin animations idle and we're going to use this notal stands idle to create uh an overlay animation so here we're going to duplicate this one we're going to change from neutral here to Millie okay and we can open it up now we can pause this move this here and over here we're going to remove from frame 64 to 300 and do this multiple times like this until we get only one frame okay like this now um next thing we're going to do is move the arm into a position so that uh we can hold weapons okay so over here on the skeleton tree let's go to uh end har first over here and we're going to rotate this uh minus 50 like this now let's go to the lower arm and rotate this only 10 like this uh now we're going to close the fingers on the hand okay so uh on index one we're going to rotate this minus 20 middle one will be 20 pinky one will be 20 uh ring one will be be 20 now index two will be 20 uh middle two will be 20 pinky 2 will be 20 and ring two will be 20 okay now the third finger so index three will be 10 middle three will be 10 pinky tree will be 10 and ring threee will be 10 okay now we can click add a key and as you can see all those modifications were added to the animation so this way if we press play the character will always uh be on that stance okay so we can pause this we can save this and we can close this so now that we have our animation we're going to create the overlay system so let's go to contents Blueprints and over here we're going to create a new enumeration so blueprint enumeration and call it e overlay States okay open it up we're going to add a new one which will be the unarmed when we don't have a weapon and another one which will be the Millie when we have a Millie weapon and we can also add a few more so like the pistol and the rifle okay save and that's it now we're going to go to our character and on variables we're going to create new variable called overlay State okay and here we're going to change this to e overlay States the enumeration that we just created so we can compile and as you can see now we have uh an option here to select our overlay State now we need is to pass this variable to our animation blueprint so that we can switch between animations um so we can uh close this now we can go to the animation blueprint and uh first thing let's go to the event graph on this update animation we're going to add a function here to get those variables okay so here we're going to create new function called get variables and here we're going to say get sendbox character because we already have a reference for it and for from here we're going to say get overlay State the variable that we just created so this one we can promote to variable and this way we know which overlay State the character is currently on okay can move this here compile save now on the event graph over here we're going to call the get variables function like this and that's basically it so now we need to go to the animation graph and apply uh the animation so here on the animation graph over here where we have the default slots we're going to move this a little bit to the right okay uh like this and now we're going to apply our overlays over here so uh we're going to create an animation layer for that so here we're going to add a new one and call it overl okay now this one we're going to add an input to it like this and uh here we're just going to say save cach Poe and call it main post so that we can use it uh on this animation layer okay now next thing we're going to do is uh select an animation depending on the overlay State variable so here we can say Blends over lay States and we're going to essentially blend uh um based on the value of the enumeration so if we click this on the active enum value we're going to bind this to the overlay State we're going to connect this over here and if we compile you can see now it says thread save and that's basically it now what we need is to right click over here and select the overlay that we want to use so in this case I'm going to use the Millie one and now I have a pin where I can connect my um animation now first thing is on the default pose we're going to say main pose to use the main pose that we saved before as the default and now here we're going to uh apply the melee animation so to do that we only want to apply the animation on the right arm okay so we're going to add a layer blend so that we can do that only on these two bones so here we're going to say layers Blends perp bone this one here on layer setup we're going to uh add two bones so one two the first one will be hand R and the second one will be um lower arm right okay so the bones that we modified over there so now we can connect this to the mil pose uh on the base pose we are also going to use the main pose okay like this and here we can connect the animation that we want to blend with the main pose okay so here we're going to search for Millie the animation that we created like this we're going to right click and convert to single frame animation so that uh we are only going to use the uh animation from frame zero and this way we can connect this here and uh that's basically it here okay so uh now we can go to the animation graph over here and we can uh grab our layer that we created and as you can see now we'll be able to connect this over here and we'll be applying our overlay State okay so we can comment this and say overlay uh overlay State okay compile save and that's basically it so uh if we go to our character now and go to the viewports you'll see uh if I change this overlay State variable to Millie as you can see now it's uh it is using the animation for the Millie weapon can change it back as you can see to normal and to Millie as you can see now we're blending the animation now we're going to change this back to unarmed okay and um the next thing we're going to do is a simple weapon system so that we can attach uh weapons to uh the hand okay so over here um on the variables we're going to create a new variable called weapons okay and this will be a actor like this soft class reference okay and here we're going to change this to map and the second one will be a transform okay so compile save and this way uh we'll have a list which will contain um the actor that we want to attach to the hand in this case a blueprint and then the transformation where we want to position the blueprint so now uh here on the mesh we can add a new child actor this one and call it weapon and essentially uh child actor allows us to use uh blueprints over here so that we can uh attach to the character now uh we'll be changing that blueprint dynamically um through the codes Okay so so next thing is to attach this to the hand so on the parent socket we're going to search for and write as you can see and now this will be attached to the hand and this way we only need to make a few modifications depending on the weapon to put it on the right position um that's basically it now here we're going to create a function that will allow us to equip the weapons so here uh on functions we're going to call set weapon or equip or whatever you want um over here uh the first input will be the overlay so the overlay state that we want to apply okay and here it will be e overlay States now the second one will be um an index which will represent the uh current weapon that we want to equip so index and this will be integer so for example on the weapons list right this is organized by Weapon 0o 1 2 and three and this way we'll be able to specify a number of which weapon we want to equip now um next thing we need is to grab the weapons variable like this and say keys to get all the uh Blueprints and now uh from here I'm going to say get and from here I'm going to say get index to uh get the index from the function inputs okay um now I'm going to promote this into a local variable called uh weapon okay so that we can use this inside this function and then uh the next thing is get the transformation so for that we're going to get this weapons variable we're going to sa find and uh essentially we're going to grab the weapon variable and connect over there okay so we're going to find um the weapon that we're trying to equip here we can say uh Branch okay and if this is true we can promote the transformation into a local variable and call it position okay um and now we need to do all the rest which is apply the overlay State and also change the weapon okay so um what we're going to do now uh first is uh essentially add a way to um know which uh weapon we currently have equipped so on variables we're going to add a new one and call it active weapon okay and uh here uh since we use the weapons we can change this to single here and we're only going to use the actor soft object reference okay so compile and now um over here what we're going to do is grab this active weapon and say if this is not equal to the weapon that we are trying to equip okay so now we can say Branch like this so um if this is true we're going to apply the overlay State and change the weapon so we can grab the overlay State variable and say set connect this here the overlay will come from uh the function inputs so we can say get overlay this one okay and uh now what we're going to do is load this weapon so we can copy this over here and say load to load the blueprints okay now we're going to cast to actor class like this and now we're going to grab the weapon and say set child actor class and we're going to set the blueprints to the one that comes from the list now next thing is to set the position so we're going to grab this weapon thing and say set relative transform this one okay and the transformation will be um the variable that we save the position over here we can uh connect this here and that's basically it okay now over here uh if we um have uh the same weapon okay we just want to inquip it so this way we can press the same key and equip or inquip the weapon so we're going to grab the overlay States and say set and set it to unarmed which is the first one then what we're going to do is grab the active weapon and say set and set it to nothing and then we can grab this CH set child acor class and also set it to nothing okay that's basically it so um now uh last thing is over here uh we have to set the active weapon like this to um the current weapon that we are trying to equip like this compile save and that's basically it now we can go to the event graph and over here um we can say one keyboards keyboards this one the key number one we're going to call the set weapon function and uh we're going to select the M overlay and the weapon that we want is weapon zero in this case we don't uh have uh here weapons yet so we can add a new one and now we need a blueprint to attach um to the hand so we're going to download a weapon from the quickel bridge so over here let's go to add quickel content sorry my computer is a little bit slow let's see if we can get there okay so um now here on the home uh we're going to search for X because I know there's some cool weapons over here okay okay here we go now um I'm going to use this the headsman X you can see that the the pivot of the weapon is like this so the weapon will uh come like this okay so you can see there's a few weapons that uh the pivot is laid down so you don't want that you want weapons where the pivot is up okay so I already have this I don't need to sign in I can click here because I have this locally on my computer and as you can see we have this x um now we can close all of this we can go to content drawer over here we're going to create new folder and called weapons so that we can save all those blueprints here we're going to create a new blueprint class and call it actor and we're going to call this bpx okay open it up and here we're going to add a new uh static mesh okay here we're going to select the X as you can see it is over here now important under Collision we have to set this to no Collision okay so that we uh don't interfere with this and now we can close this we can go to the uh weapons list that we have here on our character and select the bpx okay so compile and save and now uh if we hit play and we press one you can see that we are applying the overlay State and attaching the weapon to uh the hands now it's not on uh the right position so I'm going to show show you how you can find these positions to apply to the list so um uh essentially on the weapon if we go to viewport we can set um like the bpx as a preview so that we can uh find the positions so as you can see now if I click the mesh here I can go to advance on animation and pause the animations and this way I will have more Precision so I'm going to just uh uh change the camera speed a little bit and um on the X I'm going to move this down like this and then uh like this and then I'm going to change the grid size to one and I'm going to essentially position this like this okay so uh now we're going to rotate this uh by 180 so that I can turn this like this and that's basically it so now we have the positions for our weapon so we can just copy the location okay like this go to the weapons list and on the X just paste the location over there now click the weapon again copy the rotation go to weapons and paste the rotation okay that's it now we can go to weapon and clear the blueprint from the hands now we can clear the positions now we can go to mesh and uh uncheck pause animations so that we can have animations again okay so compile save and now if we hit play and press one as you can see the weapon should be on the right position uh we have this nice animation and as you can see if I try to Vault it just looks nice uh there's no interference at all because we layered the arm on a good position where um um the weapon is essentially um not interfering with the other animations so uh if you want to hide the weapon you can use an approach like ALS where uh whenever you uh Vault or mental uh they hid the weapon uh they make it invisible uh and then they put it visible back again okay so uh that's it guys uh I hope you liked it I hope you learned something with this and don't forget to subscribe
Info
Channel: Native Coder
Views: 5,884
Rating: undefined out of 5
Keywords: ue5, unreal engine, ue4, metahuman, metahumans, integration, fast, quick, new, method, new method, videogames, development, marketplace, locomotion, tutorial, easy, basic, beginner, interfaces, pickups, weapons, inventory, system, gun, fire, attach, unreal engine 5, unreal, engine, call, communication, interactions, pickup, grab, give, data tables, data, enumerations, game animation sample, overlay states, overlay animations, overlay weapons
Id: ZIr9RHBN2NQ
Channel Id: undefined
Length: 20min 29sec (1229 seconds)
Published: Tue Jul 02 2024
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.