Introduction to Unreal Engine 4 Animation Blueprints - Part 02 - State Machines

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
so you might have noticed that in the our anim graph here on the left side the the the node is called the state machine now i personally understand and uh what is a state machine and how they work but it's a pretty tricky concept to explain so i've looked online some definitions and i was not really happy because they're really most of them are really abstract so i found one that to me is is quite okay and could be uh i think clear for you guys as well a state machine is a is a system storing the status or the state of something so in our case that would be a character you know for video games at a given time so to give you a clear context in games our characters usually perform many different actions you know they can be by default idling they can be moving around walking running doesn't matter they can be jumping swimming falling they can be reacting to hits they can be dying they can be shooting and so on and so on without complicating the um the topic too much each of these actions can be would be a state of the state machine and the state machine itself is just the system that would enable you to based on some inputs directly taken from your controller or your keyboard for example and a bunch of conditions enable you to blend and to make all of these states communicate with each other and to trigger transitions between state a to state b so what i suggest to do right now is just to enter uh you can double click on that state machine and you see you have same thing i don't want to explain exactly what what is happening inside this specific state machine uh but i think you start to understand uh what i was explaining in the definition so we have uh here four states and they're uh they're connected to to each other using those arrows here that are transitions and these little circles next to the arrows are the definition of the condition that will allow us or not to transition from one state to the other so what we will do is actually we're gonna just go back to the anim graph uh we'll leave the the default machine as it is and we'll create our own one so just right click anywhere in the viewport and start typing state machine and then you'll have add new state machine press enter you can give it a name for example let's call it really originally my state machine and enter it okay and now we're in the state machine you can see that you have that entry thing here but no state so what we want to do is to define our first date uh so you can right click anywhere in the viewport add state let's call this this one idle and what you want to do is to connect that entry to the uh the newly created idle state so what happens is the moment we enter that state machine this is the the state will be uh will be in by default so now to uh we're going to need to define animation of idling so you can do this by entering double clicking in the in the state and see once again here we have the the output animation pose that is waiting for something that would be a right now it's going to be an animation but it can be a more or less complex chain of chain of operations so uh what we just need for the the idol here is just to drop an animation clip uh so on the red under asset browser over here so these are the animations available to that uh third person demo so just go ahead and select that third person idol and you can just drag and drop it over there and then you just have to connect those two characters there and uh so what it does is just we've just connected our animation to the output animation pose which means that at each frame of the simulation will have the pose directly coming from the animation as you can see as well that by default uh that animation that is supposed to be looped is already blooped so we have our idle so um one thing you remember compile is just to make sure that everything is is okay in your in your graph there is no error otherwise see you have here compile per person in vp successful if you had something missing i think if i just unplug that here break link and then press compile now it's successful because it's not an error but if you had if you had done something wrong and we'll probably gonna have some errors in the in the video they will be displayed here now uh what we want to do is just to test our um our new set machine so right now is still plugged to the old one uh so just drag from your own state machine to the result one it's just gonna automatically override and and delete and and the the old connection and use yours so go ahead and press compile you can save as well and now if you click play you will have your your idle obviously and if you start moving around what you'll observe is pretty funny it's just that the code in the even graph and that is actually already embedded in the third person demo is still working but we have removed every you know all the animations so the character is still moving around but idling all the time because it's still there's only one set available and that's the idle animation so press escape and what we'll do is just go back to our state machine and we'll just create the move state enter our state and what we'll do here is that we'll have the third person run animation connect it there go back to the previous state what you want to do is obviously to connect all the all these two states together okay and now what we want to do what we need to do is just to create a condition that says the moment we do something or something changes or something reaches a specific value and so on and so on please transition from idle to move so in our case in that demo we can watch the value of the variable called speed which is by default will be zero of course when you're idling right and the moment you just start moving your character around then that value will will increase to eventually reach the maximum value and then uh what we can do is just to observe that uh that variable and say if you're greater than a certain value then please start moving so to do this uh double click on your uh transition here that idle to move on the the circle um and what we will do is drag the the speed variable so you have two options you can drag and drop i don't want you release you will have get or set uh so set is just if you want to apply an operation onto your variable get is just like you want to read from it so click on on on get and now we need to to compare that that that variable to a specific value so what we need to do is to make sure that the moment speed is greater than something so it could be zero it could be one then it means that our character started to move and then we in the state machine want to to transition so to to do this just right click anywhere and you can you can write float and then the sorry the uh greater than symbol uh so you can you can select the uh absolute one it's not it's not a big deal now connect the the the speed to the the first um input here see if if you want to to understand what it does just uh you have some tooltips when you over the nodes and it says returns true if a is greater than b so a is our speed variable here and b we will be writing something ourselves so i'm gonna actually write one which means that the moment the speed is greater than 1 this node here will return true which means connect that to your result and see it says can enter condition so the moment that node returns true this node says well i can enter the transition and that transition is from idle to move so let's see if it works uh just press compile everything all right click play and now i'm pressing w yay i'm moving now the problem is when i release the w key i'm supposed to go back to idle right but our state machine does not support this yet so click escape and what we'll do uh is going to be pretty simple is just we'll create the going back transition so just create an arrow from move to idle that time uh double click here and we'll do something very similar to what we've done but just reverse so you can once again drag your speed variable here one tip if you control drag a variable it's by default a get if you auto drag a variable it's by default a set so you just you want to save the the the step where you need to to choose between get and set you have those uh keyboard shortcuts and now we'll be comparing it to the um to a certain value but that time that speed has to be less than a value so that we can detect we've been we've stopped moving so then just uh select the uh the uh less than and then same way we're gonna connect it here press press one here too and then connect it compile play and now i'm pressing w i'm moving i'm releasing i mean i'll again so what you what you can do actually i'm not sure i'm gonna be able to show it at the same time uh if you choose over here the third person anime instance and then where is my window gone over there okay when i'm playing see you can you can see in real time the actual state you're in so i'm pressing forward i'm in the move state i'm really seeing i'm back to idle so it's a good um it's a good option for you it's a real-time debugging to have a track of what is happening inside your seat machine alright guys that's it for this quick introduction to unreal engine animation blueprints over the next videos we'll be adding more and more features to progressively build more and more advanced systems thank you once again for watching i'll be seeing you very very soon in the meantime have fun stay safe and play well bye
Info
Channel: Matt Courtois
Views: 399
Rating: undefined out of 5
Keywords: tutorial, game animation, gameplay animation, motion editing, matt courtois, unreal, unrealengine, ue4, unreal engine, blueprints, animblueprints, animationblueprints, unreal engine 4, epic games, animation graphs, animgraph, state machines, unreal animation blueprints, unreal animation blueprint tutorial, unreal animation blueprint
Id: EGiKivutnuc
Channel Id: undefined
Length: 13min 1sec (781 seconds)
Published: Thu Mar 11 2021
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.