Project Description


Title: Blender Rigged Animations Into Unity
Platform: Unity Tutorial
Length: 21:59
Difficulty: Intermediate

In this Unity tutorial we’ll be going over how we can import our rigged model with animations from Blender into Unity. We’ll be exporting an FBX file from Blender then importing that file along with it’s textures into Unity. We’ll then take a look at how to prepare your mesh by taking a look at the import, rig and animation settings. For this mesh we created there animations back to back so we’ll be going into the animation editor to create three separate animation clips.

Once we have our clips ready we’ll then take a look at setting up our animator controller for use in Mecanim. Adding transitions between each animation clip to have a smooth realistic motion between the various states. We’ll then add in a C# script to control the slashing animation so that whenever we left click the slash animation will play then quickly return back to the “idle” state once completed.

Hi welcome back to the unity tutorial and restore gonna be going over how to import our blender animations from our first person rig series so in our previous video we showed you how to create our animations and now we’re going to be going into unity and importing those animations that we just created and we will be going over how to use mechanism how to create a script that controls our movement of our animations so if I left click in here you can see that can go into a slashing motion and he automatically pops back into his idle animation so that’s what we’re going to be going over today so let’s get started alright so this is where we left off in our previous video and we’re going to be exporting this with the animations so that we can use it in unity so to do that let’s go to file export and you want to select a little desk FBX alright so on the left-hand side over here you want to use the armature and the mesh so those are the only two that you should have selected all right so going to name it whatever you want and then you want to hit on export FBX already have this model ready to go so I’m just going to hit cancel right and we’re going to exit out of this and now in our unity project here let’s go ahead and start and importing various things that we need so the first thing i want to do is import my textures alright so the first one I want to go into the easy make human texture so open up your make human folder and going to the export folder and you want to click on textures alright so whenever we exported our model initially it’s going to create textures folder for us and double click on it you can see we have our two textures in here alright so we’re going to be using is the skin texture this is the texture that would be using for the arms we don’t need an eye texture because we don’t have any eyes in our model right and now what I want to do is going to my models holder and I have my knife texture right here this is for the knife model that we use and i’m going to import my rig knife this is the actual FBX file from blender once again just drag that into your project all right there we go now if we take a look at our red knife right here this is our prefab it was imported if we take a look at the model on here on the import settings you can see the model settings right here so he’s gonna factor receptor . you’re one right now so we need to change that so just drag in your rig . are your rig knife into your scene here you can see it’s very very small so let’s go back into the prefab in the project panel you want to set the scale factor of 2 1 right and apply and you can see it looks a little bit we’re right here but if we ask roll out here we can see what it looks like come on right there we go it’s a little bit dark in here so what I want to do is import a or actually bring in a light let’s go to that game object create other directional light and we’re going to move this out of the way it’s going to rotate a bit so we have some better lighting and I just make a little bit nicer and that’s going to add in some shadows right now we go alright so first off let’s take a look here we can see that our knife is not textured so we need to add detectors for that so whenever we imported the rig knife we have a materials folder was created for us now you need to try to create these materials for us I’ll it automatically added the skin texture to this material for the actual arms but it didn’t do the same thing for the knife so we just need to I dragged in the textures threw the knife slots right here for the material and now it’s textured good alright so let’s go back into the actual prefab here right now let’s go to the rig under the red section we have the animation types of two generic if you have it set to legacy it’s going to be using an older animation time basically for any type of animation that doesn’t have regular dudes legacy generic has rigs and but it doesn’t something like some like this it doesn’t have a skeletal rig would use generic then humanoid is anything that as a human skeleton type of rig right so we’re going to be using generic all right make sure they create from this model is on the Avatar definition right let’s go to the animations now the animations if you remember we created one big long animation for all three of our animation clips so if we have played down here i’m going to expand this out a bit i’m going to hit play and we can see that all three animation clips play back to back alright so what we want to do is we want to chop those up into three different animation clips and I one thing i want to go over real quick I had to change something in here for the blender file to actually get this little issue that i had with unity now for some reason you need is not like the constraints that blender has so if your knife is kind of just floating in the air even though his animation is playing there’s an issue with that and you know it doesn’t like constraints so a way around that in unity is you want to open up the hierarchy right here at the actual hierarchy for the prefab and this is a knife right here it’s called cube underscore cube for some reason so what I want to just rename that real quick better name it knife and what you want to do is just open up the basic rate right here and you want to open up the forearm got our which is the right forearm and I want to do is just dragging knife on to the hand are you basically want to make this life a child object of the hand right so it will follow that hand regardless now I went ahead and changes within blender itself i use a vertex group to kind of use the constraints with the actual mesh and the armature sort of it so the unit does actually recognize it but it’s a little bit more complicated going that route you can easily just make this a child object of your actual hand rig so that’s what you can do if you have that issue right let’s go back in here and in the animation clips we need to create a new animation clips are going to be chopping this up so first off it’s going to create our first animation clip is going to be the defensive state or the wheeled state so whenever we start the animation clip you can see that you raised his knife to is a basically near his chest along with his head as well so that’s going to be the very first animation clip we’re going to start off and type in wield right and in here is going to clamp range alright so the start frame is going to be at zero and then the end frame is going to be at and you can just type in 10 or you can also just move this little slider over here all right this is a little bit more precise so that’s where that’s why did that right so that’s our first animation clip so if we hit play we can see what it looks like all right so that seemed very first animation and it’s the very first animation is gonna be starting whenever we start our game so we wanted to wield a knife whenever we start it so for the second animation clip you want to click on the little plus icon here right and this is going to be are slashing motion so type in / and this was going to be starting at frame 10 and ending at frame 35 so hit plant range once again so type in out for the start frame right here type in 10 and then we’re gonna be ending at 35 right once again let’s preview this so it’s a slashing motion all right good to go and that was added in our third and we should clip so it’s going to be our idle state and this is going to be from 35 up to the very end so it came down clamp range and usual type in 35 for the start frame and the infirm is going to be 46 so you can see down the way it is so we can’t play with you would look like all right so it’s very jerky very a very fast because it’s a no not break not very long it’s only about 11 frames are so right so we can adjust that by kind of slowing it down right so it’s still drinks up so we can do is a go to minimize this a bit want to click on loop time it’s going to be a looping animation since it’s going to be an idle animation you want to click on new pose it when you click on new pose you mean he’s going to try to loop that animation as best as possible and you’re going to get a nicer looking animation so right now it’s very very slow so if we increase their 2-1 and very fast right now but I you can see that there’s no jerkiness right now which is basically going back and forth back and forth that’s what we want and will be adjusting the actual speed of the animation clip whenever we get into the actual animator components i am going to hit pause alright so with all that done you want to hit apply the very bottom here make sure you do that alright so if we open up our rifles are rigged knife project down here you can see that now we have our three animation clips that we just created right so in our hierarchy is going to click on our rig knife right here and we have a slot for a animator and we have a slot here specifically for a controller so we need to create an animator controller so in the project panel right-click great and later controller and i’m going to type an animator all right it’s going to apply this animator controller to our character here it’s good to go it’s going to double click on the animator controller I show this is our animator window so it’s going to drag in our animation clips that we just created to open up to you out red knife in the project panel and you want to like the actual animation clips themselves and just drag them in and you can see the very first animation clip and drag the interns orange and that basically means that’s going to be the default animation clip that’s going to be starting at the very beginning so we don’t want the idle idle animation clip to be starting we are actually want the wheeled animation clip we start I’m just going to align these is no reason at all to do this and was doing it right so I’m going to start off with the wheeled animation so want to right click on the wheeled animation and click set as default alright so now we’re going to our animation or actually this play the game look we forgot to set up your camera right so what I want to just kind of move this into place it looks like this guy’s little bit rotated alright so with a good view right here in our scene view click on your main camera what a game object along with you and right and i think it looks pretty good it’s going to hit play now all right and he plays the very first animation clip but he stops right so far so good but we want to kind of loop those animations together right so what I want to do is create animation transition from wheel to idle all right click on the wheeled make transition and click on all right so click on the transition and you can see what it looks like in here is going from Weald to idle this can be a very long transition right here so we can kind of short is down but for the wheel to idle and it’s not really necessary if we take a look at the preview here we can see what it looks like all right so that looks like the pretty good transition he starts the transition into idle whenever we finish our actual wield animation you can see at the very end here you go straight into the idle animation which is pretty good I it pause now here we have our conditions now for this one is going to work just fine and we have it to exit time that basically means that we’re waiting for the actual animation clip to finish playing before it goes into the next transition of the next animation so for this animation right here it’s perfect about for the idol to flash we’re going to be using parameters so it’s going to go from idle to flash now so i click make transition right and once again you want to click on the transition right here this i’m going to be using a parameter so it’s going to click on the plus icon right here and you want to select the pool right it’s going to be a name is let’s name it / right so the parameter needs to be the exact same here as it is in the script right otherwise your anyone out recognize it so rather in the script it needs to be exactly how its bill down here with lower case and everything right so in the transition right here you want to add in that condition with the plus icon and the very first one right here is going to change / right so slept in a flash is true it’s going to do this transition right so it’s going to remove the exit time but in the Little subtract icon on the r minus icon is always have this one condition we’re going to take a look at the preview alright so far so good now we may need to adjust this little bit if we need to later on we can adjust adjust the transition right here by just kind of pulling on these little icons right here and it will make the transition much shorter alright so i think it looks pretty good for the most part so we can just leave it the way it is right now pause so we’re going to be going with the transition here you can adjust it if you want i believe it was good the way it was before as you want to show you how to how to adjust those are transition alright so now we need a slash transition going back to idle – right click make transition go back to idle right so this time we want to use a to condition 2 1 happy exit time and just want to see / parameter so click the + icon change the top on the / and this time we want to set to false alright so if we’re for this one we want to set it to true because if we’re actually saying hey we do want to go to slash want to make sure this is true that we’re going to be playing the / animation then we stopped playing a flash animation they want to say this is false and then we want to go back to idle right so the reason we have the exit time right here is because we want this entire animation to play before goes back to idle right so sometimes you have an issue where the animation and just quickly jumps back to the idle animation and it doesn’t allow these flash animation to play entirely which looks good but weird little bit awkward so let’s take a look at what we have here it looks pretty good for the most part I don’t think we need to adjust the actual transition length right here so we can just leave it the way it is and if we need to change that we can come back to it alright so now we have all this we need to create a script to actually control the logic behind this so it’s going to right click on the project panel create you want to use AC sharp script I’m going to do it and I’m controller all right that’s going to double click it alright so we want me very well at the very top this can be for our animator and just for you guys who are not familiar with C sharp I’m just gonna be typing out private it’s going to be a private variable and we have type animator alright so we want to say Adam is going to be the name for the variable so once again it’s a private variable of type animator and it’s gonna be called Adam so it’s a little bit different from unity script or JavaScript however you want to call it a little bit kind of almost backwards alright so in the start point right here we’re not gonna be a doing much we’re just going to be saying Adam equals getcomponent animator look at on all right so we’re just setting in this brick very well right here just to i get the component of the animator and we’re going to be using that in our update function so to play our flash animation i want to use a get button so I’m going to say if input that get button and type in fire one which is the left click button on our miles right and I’m type in my curly braces and you really like to position them where I don’t want them all right there we go so we’re to type in Panem that’s a pool alright so right here we’re gonna be setting the primer which is our boolean and we say flash but lower k / and it needs to be in a double quotation right here there is a true alright so we’re going to be setting the value of the parameter which is a boolean that’s what we use set bull / – true so whenever we’re holding down our get button which is far one then we’re going to set that value to true is going to play that animation clip right so we want to have the complete opposite if we let go of the button towards a else once again it moves it in place and right so i want to have it lined up here and I’m just going to copy this paste it in and this time we just want to say false that’s what it looks like but we’re right here but i’m not going to worry too much about it alright so basically we’re saying that we hold on our far one button which is our left clip we’re going to set it to true was going to play the animation clip if we let go was going to a set it to false and is going to go back into the idle animation that’s basically all we need for this one say this right and that what we want to do is apply this to our model in our hierarchy here so just drag the script over right there we go and now if we get play he goes into the idle animation is quite fast we’ll just that but if we hold on our button it plays that entire animation clip you can see at the very end of that animation it kind of stalled out and then went to the idle state so we need to adjust that transition as well as you can see it stopped and it plays so to play and going to adjust some of these things in here so first off the idle animation is too fast and once at the speed up here so by clicking the actual state right here under the speed section right here going to 2.1 right and for the actual / transition i believe it was going backward we need to adjust this here so what we need to do is take a look at this is a little bit hard to see from here because we’re kind of kind of far away from here let’s hit play right and it looks like it’s working now looks a little bit better let’s go to test this out now to play once again so that first animation what kind of quick i think it just kind of jump that’s all I hold on my button you play the animation but a little bit slow and it’s still giving us that weird issue right so what I want to do and i believe it’s because of the script itself as it’s going to set the get button to get button down right once again is going to say this now this time whenever were just pressing the button once it’s going to set this to true so it’s going to test this out that’s impressive want to play the animation goes back and then it kind of pauses still so we need to adjust that right so the idle animation and the flash animation have some issues right here so it’s going to turn this down a bit well I’m tellin you want going to the idle animation by something like that all right I think it looks good now from the actual flash animation i want to speed this up a bit so I’m gonna set this to you – I hit play and we’re still having a weird issue and I think I know why it’s the actual animation going from the idol to the / alright so this transition is quite long so we want to select join us down quite a bit and it’s going to preview this right there we go look like in a fixed it all right there we go now you could use get button you would have to hold down the actual button for the actual animation be playing but this is a little bit more realistic you would want to kind of just press it once and then go through that animation and I’m actually jump back into the idle animation all right so you can keep tweaking this if you want but now you should have a good understanding of how to use blender animations within the Union how to set it up for mechanism so i hope you enjoyed this tutorial thanks for watching!