Animations with Layers in Unity3D - Unity Devs WATCH THIS

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
every video game needs characters and i'm a terrible artist so one of the things i've been doing recently is hiring other artists or hiring actual artists to make me some really cool sci-fi 3d models some characters that i can share with you that i can give to my students in my courses and then i can make videos out of and that's what i've done today i've got a video here with two of the latest characters and i wanted to show off two different things first is how to set up some simple animations which most of you will probably already know the other thing is a little bit more complicated i'm going to explain how to use animation layers so you can stack up a bunch of different animations and we'll get into some cool and interesting unique animations that this robot's got that i think you'll probably enjoy let's start with the basics first i've got my two characters and they're both in my project i've got my vendettorian the alien that was made by an artist on fiverr and the robot that was also made by an artist on fiverr i'll share their links down below by the way if you're curious on contacting one of them to have them mix smart for you so i've got both of these characters and they're in my project i've got the vindatorian selected and you can see on the rig selection of the inspector he's set to humanoid if i hit the configure button you see that i've got all of my transforms assigned and they all have this mixamo rig which to me is a good indicator that the miximo auto rigger was used to set this character up now that's actually perfect because that means that i can upload my character to mixamo just like this and then go grab whatever animation i might want like a random strut walking or a punching animation or whatever other thing i might want to grab i think i'll download the punching animation to download the animation i hit download choose fbx for unity and choose without skin hit download and then just save that file off into the animations subfolder well right now i'll drop it into my downloads folder and then from there i'll drag it into my animations subfolder let's do that now i've got my vindatorian file right there and i go find oh i don't have an animation subfolder so i just drop it right in here and now i've got my new animation my punching animation for the animation i need to go over select the rig on the inspector with that animation selected choose humanoid and then choose copy from other avatar hit the little search box and then find my vendettorian avatar hit apply and now i can use this animation on my character if i go over to the animation tab is that i can press play and watch the animation play but if i drag my character into there i can actually see it playing on my character now that we have the animation let's look at how we can use it i'll go select my vendotorian which already has an animator on it this gets added automatically to anything with a humanoid rig and it has a animator controller on it the controller is something i've created manually you can do that by right clicking in your project view choosing create and then finding animator controller and clicking that give it a name and then assign it once you have a name there i'm going to delete that duplicate one but once you have one you can just drag it right in here and double click to open up the animator controller window you can also access this under window and then i believe it's animation and animator there it is you can open it either way now that i've got my animator window open you can see that i've got a base layer over here on the left and i've got a couple different animations if i press play you might notice that those animations loosely match up with the animations available for this alien i've got a dance i've got an idol a drunk standing idle an mma pose and a rifle holding pose no rifle in his hand but he's got the pose so how do we add our new animation to this animator we'll go back over to the animator and then find in our project view the new animation that we've grabbed that punching animation i'll expand out the fbx file so i can see the punching animation underneath it and if this says something like miximo animation instead of punching you can click on the animation file the fbx here and then find the actual animation clip and rename it here you may also have duplicate clips here or two clips just check to make sure that the clip that's actually used is the one that has a time that is more than zero seconds sometimes you'll see a zero and zero start time kind of empty clip there you can just remove that if that happens to occur so i'm going to take my punching animation and drag this into the animator i'll grab it drag it anywhere out here that i want i'm just going to take it right above the rifle idle though so i can keep things nice and clean and then i need to make a transition so that we can transition into this punching animation actually i lied there's one other thing i need to do first i need to check this loop box so that my punching animation will loop and not just play one time i want it to continue to loop and stay in this animation until we switch away i'll scroll down and choose apply and then we'll go at our trigger or our what is this theory transition trigger well we need a trigger and a trigger for our transition so let's go set that up i'll just stop talking about it and we'll do it we're going to go to the parameters tab here this is the layers tab and this is the parameters tab they look like buttons but they're supposed to be tabs we need to go add a new parameter and here you might notice that we've got parameters for all of the options that we had in that menu a moment ago and they match up with these ones here we're just going to hit the plus button choose trigger and then we're going to name this punch we're going to choose the any state we'll right click hit make transition grab and drag notice the line that kind of follows along with my mouse and i'm going to drop it right on to punching should make a line straight to punching then i'll click right here on the arrow anywhere on the line is really good but i'm going to click on the arrow and we'll get the inspector for that transition this is the transition from any state no matter what state we're in into punching this will happen whenever the condition is met and the condition needs to be added by hitting plus and then choosing the trigger that we want so we're going to go down and choose punch and whenever punch is set this transition will happen let's save press play and watch what magically happens we now have a punch option here and i can press it and he starts punching all right let's stop and demystify things a little bit dive into how that's actually working so when i choose one of these buttons what's actually happening is the animator for my vendettorium this animator when i select him is being updated or more specifically the controller is being updated well the animator is being updated with some triggers being set that are modifying the way the controller works let's take a look at that i've got the animator window right here and i'm going to drag this down below so we can see the animator and the character at the same time when i choose a trigger on this animator it should switch from my any state to whichever state that i've selected for that transition on our new one it's punch so if i choose punch it should transition if i choose the rifle idle i click it and trigger it and see that it switches into rifle idle goes right up here because i have that condition set same for the mma option you saw that little line probably pop right up there i can hit it again you see the line go it just transitions right into it and i've got that for all of these now these buttons they're simply setting those triggers so if i click one of these watch the transition happen you might not see the little light appear here but you do see the transition happening and the way that that happens is also relatively simple it's a little bit of code and it's some code that i'll make available for you at the link right here if you're interested just go check it out you can download it but i'll show you really quickly what that code looks like and how it's set up i have my canvas here just a standard old unity canvas and then underneath it i've got two panels let's go take a look at those in 2d mode i've got two panels here covering my top left and top right corners they're both just anchored to those corners they're 600 by 600 and they each have a script on them an animator panel script they're linked up to a specific animator the left panel is linked to the robot animator the right panel is linked to the vindatorian they also have a reference to a button and on their start they loop through each of the referenced animators parameters and then if the parameter type is a trigger i add a button to my panel so i just create a new button the add button method will instantiate a new button using my button prefab which is actually this really cool button from a asset pack that i'll link down below if you're curious about it i really like using it it's this neat sci-fi asset that has really cool buttons and ui elements so definitely check it out so i'm using that button though and i instantiate it loop through all of the children the text objects just set the text to match and then we add a listener so we get the button component of our button actually i don't need to do that let's get rid of that we just say button dot on click dot add listener this will add a call back just like if we press the plus button in the inspector and the callback will call animator.settrigger and it sets it to the parameter and here i just use the name hash because it's more performant than using the name the name would work as well and again if you want the code you can just grab it in the link down in the description below or go to game.courseslash ap all i ask is you please hit the thumbs up button or drop a comment and let me know if it was helpful in handy it really makes a big difference so i definitely appreciate it now that we've covered the basics let's jump over to the robot and take a look at animation layers and see how they can come in handy and what we can use them for i've selected the robot and you can see here that his animator controller is a bit different it's a robot animator controller that i've made for this character that doesn't have nearly as many states in its base layer we have an idle state and a dancing state i can choose the dance option and make him dance or i can make him idle i used to have a fly option but i apparently took that out and broke it so what are all these other options where are they how are they working let's try them out let's click on one and take a look if i hit the toggle head button you'll see that my head little antenna starts spinning around in circles i can hit the toggle ears and right now it's just toggling and spinning that left ear but it could toggle any number of ears that i want watch what happens when i hit the eyes they start spinning around in goofy circles and then the hacking one is actually part of a separate hand got multiple hands here there's one where he reaches out does some hacking and we'll be doing an animation rigging video on that really soon so keep an eye out for that if you're interested make sure that you subscribe like and all that stuff and just let me know in the comments so that i can make it more of a priority so how are these working without changing this animation notice that our idle animation is playing still and if i switch to dance my eyes still spin the head still spins everything still works oh and the brain if i hit the brain the brain will grow and shrink kind of animate a little bit uh a little bit creepy but i thought kind of cool just needs some neat particle effects by the way the particle effects i've put over this uh head i'll link those down in the description too really cool youtuber that's made some awesome particles that happened to be on sale and i thought hey these are awesome i actually need to reach out to him about maybe doing some stuff together i think that'd be a lot of fun all right let's continue on though i'm going to stop babbling and tell you how these layers work so we've got all of these toggle options and you can see if i switch back into idle so it's a little bit more normal when i hit the head option it turns the head on and off and you're noticing that nothing changes here what's actually changing is in these layers so i'm going to go to my animator and choose layers and you can see right now that we're on the base layer that's the one that's highlighted i can go through the different layers and select them let's check the antenna layer the antenna layer is actually spinning the header playing the spin head animation and if i choose the toggle head option notice that the transition switch is out of spin head and into none let's take a look at these transitions and then we'll see how the layers are set up themselves so the transitions are relatively simple they're almost exactly like the other animation transitions on the default state of none we have no animation at all so if i click on it you see that this is just the default empty state you can create one of those by choosing create empty create state choosing empty right clicking and then hitting set as default layer i'm going to undo that though with a couple control z's so that i've got my default layer here then we've got a transition that goes into spin head based on the toggle head trigger being clicked and then leaves based on the toggle head trigger being clicked as well we have the has exit time on for leaving so that it actually finishes up the animation leaving but off for starting so that it instantly starts and pops into that animation let's try it one more time i hit toggle head and you can see that it runs let's try the oh let's go for eyes i'm going to hit toggle eyes and watch the eye spin hit it again and watch them stop let's go take a look at the eyes layer so we can see what's happening there same exact thing so you can see this is really just kind of a duplicated process i've got multiple layers on each layer i can toggle on and off one animation we could of course have multiple but i like to separate them out since i've got a single thing going on per layer now let's go through the process of creating a layer so that you can see all of the steps and make sure that you're not missing anything i'm going to actually delete our antenna layer completely take the animator drag it up by the game view and then we'll recreate the antenna layer first though let's just quickly look at the vinditorian i'm going to go find the venatorian and notice that he doesn't have any other layers on his animator now i'm going to switch back i just wanted to show what it looked like when you just have a default view base layer no extra layers the robot with a whole bunch of layers let's hit the plus button now and add in a new layer this will be our antenna layer and then in our antenna layer we need to find the animation to spin our antenna so i think it's called a-n-t-e-n-n-a let's see is it spin maybe it's called spin something spin head that's what i called it so we've got the spin head animation and that's the one that i want to use i'm going to drag this out into the canvas for our antenna layer and now if i press play let's see if the animation just plays or not so you might wonder and kind of guess whether or not you think the animation is going to play and notice that it's not the animation isn't actually happening just adding it there on another layer isn't quite enough we need to do one other thing let's take the animator and drag it down here the other thing that we need to do is hit the gear and then adjust the weight we need to drag this weight over to the side all the way over to one so that it's weighed in all the way and mapped in so that it actually animates i guess the reason for this is that you can mix and match and stack up your different layers so you have part of a run plus part of an attack playing and kind of weigh them differently you can also scale them up over time so that it starts and stops or a bunch of animations kind of blend across each other with the weights there's a lot of different reasons for it but we want to change this weight to one and we want to change the blending to just be additive so that any other animations that are playing also get added on to this head now one other thing that we need to double check when we're working with this animation is that the avatar doesn't have the bones for this animation mapped up to something else let's go take a look at what that looks like if i go find my robot full let's go find if i can find my robot where's my robot i probably just click in the folder that he's in so if i go select my robot model and i go over to the rig and then i choose configure i need to make sure that the bones that i'm animating with these custom animations on the heads the eyes and everything else aren't assigned as part of the body the head or the hand i actually ran into that issue with the head the antenna was being grabbed as one of these accidentally and with the hacking on the hand one of the wrong thumbs was being wrapped i had to fix those up in here and it's something that you'll need to double check as well if you start doing custom animations on different layers let's finish up that animation layer so i've got the spin head how do i add the toggle in there so that it actually works because i have the parameter for toggling head just doesn't do anything anymore well to do that i need to add in a default layer so i'll hit create state empty we'll call this empty oops i renamed the wrong one we'll rename the new state to empty we'll make that the default layer state and then we'll make a transition into spin head i'm actually going to rearrange these so that they just kind of match with my other ones right click choose make transition in the spin head choose the transition hit the plus and then we'll choose the condition for spin head or toggle head is what i've called it and we'll do the same transition out of spin head using the same conditions we've got to go choose toggle head so that when we click it again it turns off again the has exit time i want for the exit only not for the enter so i'll turn that off there now if i hit my toggle head i expect that it should start oh it's not starting and then it should stop start and stop let's go take one more peek at this i've got my spin head there i've got my layer up my layer weight got dragged down i probably did that when i was playing there we go drag it back up while i'm not playing press play again and now my spin head option is back in and my layers are working all right i hope that this was kind of helpful for you i plan on doing a lot more different animation videos and diving into some things like animation rigging masks and quite a bit more if you're interested in that stuff please just drop a comment down below let me know which things specifically you think are interesting what things you think i got wrong what things you think i should maybe talk a little bit more about and please hit the thumbs up button subscribe share the video makes a big difference also if you want to grab these models let me know which one you think would be best or coolest to release first and i'll get that out you know whichever one wins i guess pretty soon except for the robot one is actually going into my game architecture course almost immediately so if you're interested in grabbing that right away if you're a member of that you'll be getting it soon so see you all in the next video thanks again don't forget to like subscribe and have fun building games and stuff
Info
Channel: Jason Weimann
Views: 39,444
Rating: undefined out of 5
Keywords: unity3d, unity, unity animation, animation layer, animation layers, unity layers, unity animation layers, unity animation trigger, animator trigger, unity trigger, how to use animation layers, tutorial, animation, animation tips, how to animate in unity, animate in unity, unity 3d, game dev, game development unity, unity animation tutorial, brackeys, jason weimann, dani, codemonkey, unity technologies, unity animator, animate unity, animate in unity 3d, animatorcontroller
Id: Qwy3rEDXqxA
Channel Id: undefined
Length: 18min 36sec (1116 seconds)
Published: Mon Mar 14 2022
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.