Tutorial: Animation blueprint - Unreal Engine 4 + Unreal Engine 5

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments

Feel free to visit my channel of tutorials. :)

Video link: https://youtu.be/40-V4kYDe1U

Channel link: https://www.youtube.com/channel/UCPqAMQsTxwdQfC4_GsJrwkQ

👍︎︎ 3 👤︎︎ u/LeafBranchGames 📅︎︎ Jun 19 2021 🗫︎ replies
Captions
[Music] welcome to this tutorial in this tutorial we're going to be looking at unreal engine 4 and unrelenting 5 when it comes to animation blueprints we're going to be looking a little bit at how they actually function and give you a basic understanding of why certain things happen and how they come together so let's jump into it so here we are inside of unreal engine 5. uh this will be working the same way in unreal engine 4 as it does in unreal engine 5. it just will look a little bit slightly different visually but you should be able to follow along regardless which version of the honorary lending that you're using so what we're going to be doing today is we're going to be looking at the third person character that is in the third person template and just go through how is the animation blueprint set up in the beginning and see how does the different parts work and we'll also talk a little bit about how you expand upon this so to begin with to find your animation blueprint you can just either click your third person character in the map and then go to edit third person character over here so you'll get it over here or you can go to your third person blueprint folder and find it over here and from here then you have the ability to go to your mesh in your components tab and then you can see what kind of animation blueprints it's using here you can see it under anime class so to begin with a a a mesh can have a either a a specific animation asset being played that means it's playing one animation a specific one like shooting a gun or something like that or you can use an animation blueprint which dictates how it how it is moving um and behaving when the character moves around in the world so this means that when you want you you can either have all of your logic inside of the animation blueprint let's just go to animation blueprint to begin with we click on this magnifying glass to find where the animation blueprint is and then we just open it up um so so you can either have it so all your animation logic is in your animation blueprint or you can make some kind of hybrid where you have some in the animation blueprint and then you have some other things being called in your code otherwise for like things like montages or whatever you want like that so then you have a little bit of flexibility of how you want to make use of it but the essence of a animation blueprint is it consists of in the beginning like the third person character here it consists of a event graph and an animation graph so the animation graph if we open this up is this is what it looks like to begin with and this is what it looks like when you start so the output pose is what the actual animation is going to look like for your character uh in the game so in this particular instance it's determined completely by the state's machine here so the state machine here determines what will the animation look like sends the animation to output in the output pose and the mesh in the character will be looking like whatever this state machine has decided it to look like if you wanted to have something like a montage playing that should be blending with this or like completely overriding whatever this says so you can have something like character punching or something like that you would put in a slot here in between like this a montage slot and then you would like plug it in like this and then this so that means that as long as the state machine is playing if nothing is being played in the default slot over here as a montage then it will just be passed in and pass through and you'll have whatever the state machine says but if you have a default slot here that means that a montage is able to override whatever this says allowing you to do for example the punch that we talked about earlier and how the montage is deciding where to play is dependent on this default slot you can have a slot with a different name so the montages play in different slots and such things for now we're going to leave that like this so let's go talk a little bit about our state machine if we double click on the state machine we get into this grid here and if you are not aware of what a state machine is a state machine is a a bunch of logic that allows you to move from one state hence the name state machine to a different one so for example when you're sleeping at night you're in the lying state you're lying down and to get up you first maybe sit up in your bed and then from there you can go up to standing so you would have a state for lying a state for sitting a state for standing and then when you're standing you can also start moving around which means that you can have some in this case like we have here we have an idle and run state so this state is handling both standing still like when you just stood up from your bed and when you're walking away from your bed so what the state machine is basically is a way to organize how you can transition between different states to make your animation look good so for example if you were lying in your bed you would not immediately be in your standing animation because there would be a gap in between so you would have this sitting animation in between so you would have the the transition of lying to sitting to standing uh as a general example of course so what we have here is we have an entry point the entry point is determining where when this blueprint starts playing where where should it begin so the begin state for this state machine is the idle and run from idle and run you can see that it has arrows to other squares and each of these squares represent a state so you can see that from idle and run you can't go back to the entry because there's no arrow going there you can't go from idle and run to jump and because there's no arrow there the arrow is only going in this direction so this state says that the only other state we're allowed to go from here is to jump start and jumpstart is only allowed to go to jump loop and jump loop to jump end and jump and back to idle and run now what determines how you transition between states is something called a transition rule so here you can see we have the idle run to jumpstart transition rule and what it says is it shows a boolean that is is in air so we have logic that keeps track of if we are in the air and if we're at any point r in the air then this state machine will know that okay i should not be idle running anymore i should be moving into jump start and jump start on the other hand it will keep track of when third person's jump has started as long as it's within 0.1 you can see there that means that it has a time so this specific transition has a time as the rule for transitioning so after 0.1 seconds it will go from jump start to being in jump loop and jump loop on the other hand it will keep looping the jump continuously because you don't know how long you're going to be in the air you might just be jumping from the ground to the same level where you jumped from or you might be jumping up to a box that's higher from where you started which means that the jump loop would be shorter or you might jumping off a cliff and you might be falling for several seconds or minutes or who knows what and that means you have the jump loop here to make sure that your jump is as fluid as possible going from an animation that shows the start of the jump shows a looping animation that shows something that feels like you're falling and a jump end which is sort of a landing animation so when the jump loop here determines that we are no longer in the air it's taking the same boolean as this one over here but it's checking it in reverse it has a knot in front of it then it will allow it to transition to jump end and jump and in the same manner as jump start will just after 0.1 second transition back in title run so that is how that works and to set these up you can double click on one of these transitions and you'll get to a transition rule code piece and this is basically just saying the result here is saying what is the condition that you want me to be able to transition from the previous states to the other state that i have been assigned to so all of these look the same if we go back to our default here they all have these results here but the code that is triggering how the transition looks different but the result is obvious here so you just set up a boolean expression of how you want to transition so in this case we have have here that you jump loop to jump in so it is supposed to determine when we're supposed to be playing the landing animation we do that by determining if we are in the air and then putting a knot in front of it so this wants a true to be able to go through to the next state which means that if we are not in the air and we invert that it will become true and that means we can land right it might be a little bit more difficult to understand than this one which just checks if if we are in the air okay we're allowed to transition into the jump start animation but this is just a matter of getting used to it so that's how transition rules work and these states they can look quite different as well so for example this particular state over here which is the jump start state the one that starts the jumping animation it just has a specific animation in it which it's plugging into the output animation pose and this output animation pose is the one that we saw in our anim graph over here it's the one that's getting fed out here and being fed back into the actual mesh so in this particular instance what we're telling it to to send here is the specific animation that plays over here which is third person jump start now third person jumpstart we can go and find over here in the asset browser we can double click that and we'll see what it looks like so this is the animation that it plays so what happens is it's going to be playing this for 0.1 seconds like we told before because that's how long before it allows the transition to the next state so if we pause this what will happen is each frame that goes by it will determine where am i in this animation like for example here we are let's say we are in this frame where this animation is being this is how far we've come in animation then this is what's being transmitted transmitted to the mesh as this is what you're supposed to look like right now and it keeps doing this all the time here until it has gone for 0.1 seconds so it just keeps sending this data to the mesh now if we go back to the animation blueprint so this is a fairly simple example it's just playing a specific animation and sending it out there are more advanced ways of handling this like if we go to the idle run for example all of these three here are the same they have one animation that they're playing the difference is this one because this one is going to be looping which means that it has the loop animation checkbook checkbox set here to allow it to continuously look like it's falling which is the animation over here you can see in the little preview window there but when it comes to the idle run this is a little bit more complex and here you can see we have something here that says blend space player so this is a blend space meaning it is allowing by taking in inputs like in this case speed determine how fast or how is this animation supposed to look like so this particular blend space is this yellow little icon over here that says i'll run 2d if we open that up we will see what it looks like so um this animation allows you to if i hold shift now here and i move my mouse cursor you can see that it's moving this green x along the line and this represents zero here represents the zero speed and over here you can see 375 speed is the max these are the values that determine what this animation will look like so if you have the speed of for example over here let's that's 94. so let's find the play button over there so if we put it over here by 94 it means that if the player is inputting 9 or 92 in this case now 92 speed this is the animation that it will be feeding for every frame as the output pose if we were to have our speed over here by 39 this is the animation that it would be sending and if you were having the max speed then it would be running and you can see that this is the animation that it would be sending so a blend space is just taking some parameters and then figuring out how it's supposed to blend one or multiple animations to give you an output and this is determined i go into more detail about this in my plan space tutorials so feel free to check that out if you want to but the basic gist is that we have one animation over here which is the third person idol which says that if we have zero speed we're going to be standing like this just breathing if we reach this step over here 93 we're supposed to use the third person walk animation instead which is the one over here which looks like that and then at the top here we have the third person run which is this animation which is supposed to be playing but that means that these animations only play at these specific speeds by themselves the blend space allows us to say well what was what will it look like if we're in the middle of the walk and the run then we get this half and half between the walk and the run making it look sort of like it's jogging for example or half between idle and walking and then it looks like it's slowly meandering forwards you see so the blend space is basically just blending several animations together to get a end result and then transmit it further and that is what this is doing so it's a little bit more advanced than normal that we saw on the the jumping but it's doing the same thing it's sending out results here so that is the basics if you wanted to expand upon this what you would do is you would go to your graph over here and then based on how you reason that you are supposed to be able to transition for example if you have an idle run and you want to have a crouching state where you start moving around in a crouch state what you can just do is you right click and then you add a state and you call it something descriptive like crouch and now we have a crotch date so how you reason when it comes to states is okay from idle to run i want to be able to reach the crotch state so then you drag from there you have this little bar around it you you hold down click and drag and then you release it on the bar on the other state that will allow you to create this connection and then you can also reason that okay well from crouch i'm supposed to be able to go back to idle and run as well and now this makes sense and then you would have to set up these transitional rules of course just like these ones but you would probably get a different boolean something that says like crouch and then that crouch variable would be set from your character blueprint which would have some kind of button for crouching or something along that nature um but you might reason well i want to be able to transition to crouch from jump start and i want to be able to do it from jump and then i and then you get this like criss crossing of a lot of wires like this generally this is not good what you can do is you can reason that in this case it's it's a bad example because you're not supposed to be able to transition from jumping to crouching most likely but let's say we had another state here let's add a state called prone you might reason that you're supposed to be able to reach prone from crouch and you might reason that you're supposed to be able to reach prone from idle and running also which means that we're instantly getting this slightly more complex grid and this might be accurate however when it comes to something like transitions like this it it is you need to be a little bit aware of how you're dragging your connectors to allow states to transition because um a state like idol for example is something that you're you're you're normally going to be in it's like when you're running around and worse you're standing still it's a normal state so it might be okay to have something like this but you're only allowed to transition between idle run to prone and idle around the crouch and not between them like this again this is a determination that you have to do based on what you feel is right for your game or your project of course but it can easily be quite cluttered if you have all of these states and then you add another one that's like uh what's a good example let's say um aiming okay i need to add my state first before i actually name it so state and let's say so then you have an aiming state an aiming state is supposed to go from run to idle and then back but you might want to do it from crouching and then you get this you actually have to do this and then you want to go from prone to crouching and then you want to be able to go back and then you're like okay what i also want to be able to proname and then i have this situation and you see that it can quite easily start get a little bit messy so it's a good idea to plan a little bit when it comes to your states make sure that you have a logical and functional hierarchy when it comes to state transitions just some food for thought really anyway um let's get on to the next part about animation blueprints and that is this part which is the alien graph or event graph and to begin with this is what it looks like it has something called an event blueprint update animation which has some basic validation oops basic validation of the pawn owner and it's getting a movement component it's checking if it's falling it's setting if it's in the air it's getting velocity and it's setting up speed this is basically just making use of your character that has a movement component in it to determine if it's falling and then checking some speeds and stuff like that because it needs the speed to be able to determine where the the idle run state is in the blend space that i showed earlier so this is why this is happening so every frame this event will happen and you need to calculate all the data that is necessarily necessary for your animation blueprint to show in the different states that you have to to make sure that it's actually showing the proper output pose so this is what the this event is basically for so it's just checking if i'm in the air to make sure if i'm doing the jumping animation and then it's checking what's my speed if i'm doing the idle run blend space and then as you keep making this blueprint more advanced you'll be adding more and more calculations here to check and get information for your blueprint and blend spaces and such in addition to this this might not be like super awesome to always check if this is valid all the bloody time but in some cases it might be it's up to you to determine um you might want to offload some of the logic somewhere else like yeah normally have a begin play when it comes to blueprints this is not technically the same thing as a begin play for the animation blueprint because if you see here it says executed when begin play is called on the owning component so that means the actual character that this animation blueprint belongs to or the mesh rather but here you might be able to like make get some references to certain objects that you need for calculations and things like that making sure that you just do it once so you don't have it in the updates all the time and and you might not gain a whole lot by it but every little bit might help in the big picture so just something to keep in mind and there are also some other events in the animation blueprint that you can make use of if you want to like delve deeper into offloading some of the data and the calculations that you want to do anyway so again if you wanted to expand upon this and you had made these new states then you also have these variables and you see here we're actually storing our in-air variable boolean and our speed boolean over here and these are the ones that we're setting over here so if we were to add our crouch for example we might add a not available okay it's probably because i named the state crutch so crouching then as our boolean which we would then be checking here to see if actually we would probably do something like implement possibly an interface or some other way of handling this in a clean way but you can also from your third person character get your animation blueprint from here and then send to it and say i want to set that my character is now crouching which would then make the blueprint understand oh well okay he's crouching then we go to the anime graph and then it checks the the transition here and says okay well he's supposed to be crouching so we're supposed to enter the crouching state and that means that it's going to be here when it starts outputting the poses again so it's fairly straightforward on how you want to expand upon this but again unless you want to have this kind of mess that i have right here you you want to give it some thought and another thing that's very good about this is that since the movement component is replicated by default for a third person character then um that means that things that you set up in the animation blueprint is generally going to be fairly straightforward and easy for you when it comes to multiplayer because it will work fairly easily out of the box so to say [Music] hopefully you found this video helpful if you liked the video leave a like if you did not like it leave a dislike leave any suggestions or comments you might have down below subscribe and share this video if you want to see more like it in the future that is all for now keep on learning take care you
Info
Channel: LeafBranchGames
Views: 915
Rating: undefined out of 5
Keywords: Unreal Engine 4, Unreal Engine 5, Beginner, Tutorial, Animation, Animation blueprint, State machine, Game development
Id: 40-V4kYDe1U
Channel Id: undefined
Length: 26min 4sec (1564 seconds)
Published: Sat Jun 19 2021
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.