Exporting animated character from Blender to Unity - full tutorial

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hi everyone in this video i will show you how to export your animated character from blender to unity i will show you the way i export my character in production formulara i'm not pretending this is the best way to do it nor this is the only way but it does work pretty well for me and this is the way i've been using for four years now we will cover the export option an fbx overview inside of unity and how to create an animator in unity and plug your different animation let's get started again there are different ways you can export your animated character to unity some people tend to create one single action where they will input all their animation one after the other this way you get one single animation that includes every animation in my case i prefer to get my animation separated in different blender actions i have a base action where i do my keying set that is the current active action and a bunch of other action that are rig actions but also my animation set for the character back into object mode the important thing is to make sure that all your object have an even scale of one whether it's the amateur or the object that i'm going to export the character and its gear it's also ideal but not mandatory that your location is set to zero meaning the origin of your object are aligned with the origin of the world you can choose whether to use the nla editor or not while exporting in fbx but either way i advise you to clean up your file before exporting if you're not the guy in charge of exporting the fbx 2d engine then it's better to deliver a cleanup file so if you have any active strips in the nla editor just select the track and press x to delete them you won't be losing your action if you have activated the fake user which i advise you to do whenever you are creating an animation with the default track selected i will select my keying set or my rest pose animation if you will you can also simply go to the dope sheet action editor and select the action you want to use as default since we have cleaned the nla this is going to be our default animation for the character so it's going to be your rest pose or rest animation also in the game engine the next thing we have to do before exporting is make sure that the bones that are not skinning our character meaning that are not deforming our character are currently not set to deform on my character rig i've put all the deforming bones onto a specific layer and all the control bones on different layers if i select one of those deformation bone i can see that the deform option is activated this deform option is also activated on the root of the character which is a controller but i want to export it too because it can be used by our developer whenever they want to move the character in space or it can be used as a reference point for the rig in engine you can enable or disable the deform option of several bone at once by selecting them and pressing shift w and select deform then you can enable disable or toggle it before exporting to fbx some word of our sponsor this tutorial is sponsored by myself if you want to learn all my rigging technique or if you want to create stylized character from scratch you will find all you need on my gumroad page use the code p2 design and get 10 percent on whatever product you want exporting is pretty straightforward the first thing i do is that i just select the object i want to export by character it's gear and amateur then i will simply go to file export and choose fbx from there the first option i will choose is selected object this object is in the include menu where you can specify what kind of object you want to export but using the selected object only will override any of the object types so you are sure that you are currently exporting only the amateur and the mesh if you don't do so blender will export in the fbx all the items in your scene when exporting to unity you want to use the forward direction as positive z it can be tricky to figure out which axis to use because it varies from a software to the other or it varies also from an engine to the other freya homer has output a nice chat that could help you and i truly recommend you to follow her on twitter because she shares a lot of game engine information in a very comprehensive way we want to use a scale of 1 and you should enable apply transform if your scale was not set to 1 it will apply the scale and it will export the animation more properly i keep the geometry setup as it is if you have a solidify modifier for example it will apply it and your model in unity will look like your model in blender in the armature option we will get rid of the leaf bone leaf bone are automatically created at the very end of a bone chain for example on the arm chain you will find this kind of leaf bone on the tip of the fingers on the torso chain on the tip of the head they define the end of the hierarchy but we don't need them in unity we need to activate only different bones so that we will only export the bones that we have tagged as deformers and so it will make our fbx lighter and its hierarchy way cleaner in the bake animation menu i will keep everything as it is since we have cleaned the nla editor we can keep the nra strips it doesn't matter all the bones will get a keyframe by default and since we are exporting all the action separately we can keep the force start and end k the sampling rate define the rate of frame that has to be evaluated during the export so we can keep it to 1 so that every frame will be read and written into the action that is exported by default the simplify option is set to 1 and while it makes the export a little faster the problem is that it's going to slightly modify the interpolation of some of your curves and you will lose animation certainly while it's settled you won't notice it most of the time on face animation sometimes it can create some glitches so i reduce it to 0.1 now we can click export and we will start working in unity for this tutorial i'm using unity 2019.4.12. i advise you to use unity version upon 2019 because the fbx import has been greatly improved i will create a new project and select 3d as a base template and click create in unity with my sample scene open i will simply create a new folder in the project hierarchy under assets and i will then create another folder called texture where i will drag and drop all the texture of my character and i will drag and drop the fbx directly into the character folder if i now drag and drop the imported fbx directly in the scene i will see my 3d model in its rest pose being imported and it's currently correctly aligned with the unity world space the first important thing you have to understand is that an fbx is a library and when i unfold it you can see that we can find our different material the meshes but also the object the armature and all the animation while if i check our character in the scene i can find the object the armature and all the deformation bones we have exported we need to cr we need to replace the material of our character so i will create two new material one with the name of the character duplicate it by pressing ctrl d and rename the other upon gear then in the texture folder i need to tell unity that our normal map are currently normal maps by setting the texture type to normal map and click apply if you don't do so unity will warn you in the latest version and will convert it automatically as in blender eevee materials can have different type of shaders we are using a specular workflow for our game so i will switch to standard specular from there i just need to drop my textures onto the different slots since the inspector change each time you select an object what i will do is that i will select the material and i will lock the inspector from there i can easily drag and drop my different texture into their texture slots to assign the material to our character we can simply drag and drop the material directly onto the object in the 3d space or we can do it directly by editing the fpx and i advise you to do it on the fbx so that it will be saved on the original data so let's have a closer look to our fbx in unity as it is selected i can see it in the inspector and jump into its material tab by default the material tab is empty this is why we add to drag and drop the material onto our model but we can see that those material slot have the same name as in blender so i just need to drag and drop the newly created material into the corresponding slot each time each time you modify an fbx you have to click the apply button the benefit of adding those material at the effects level instead of our character instance in the 3d scene is that each time i will drop a new character or a new instance of the character it will already have its material assigned in the model option of the character you can see how it was imported especially regarding the scale so by default it's okay because it's considering one centimeter in blender as one centimeter in unity so there are a lot of options that allows you to debug or add custom settings to your character but we will keep it to default if you are using your own rig with your own animation then keep the animation type to generic the humanoid setup allows you to define what are the legs what are the arm the torso etc of your character to remap different animation from one character to the other there are a lot of tutorials on youtube about that to be able to use our rig we need to set an avatar the avatar is kind of the behavior and the options that are affected to the rig since i'm using a unique and custom rig i will choose create from this model it will bind our current rig to our character using the standard four bones influence per vertex you can also choose the root mode whether you are using a specific bone in the armature or if you set it to none it will use the object origin as the root so let's apply those modification and jump into the animation when we go to the animation tab we can see the full list of animation available in our fpx it's the same list we can see in our fbx hierarchy if i want to preview those animation i need to select the fpx and in the inspector i can select one of the animation and play them in the preview window in the lower right corner of the ui so my character has a lot of different animation songs are in-game animation but the first one are just animation used by the rig itself in blender so what you have to understand here is that what we see here is the library of animation that can be used in unity these are not the animation contained in the fbx so i can get rid of them i will just select them and click the minus button here i'm not deleting those animation i'm getting rid of them in the library so it's very close to the way blender deals with data i can create a new slot and then search for the animation i want to assign to this slot and this animation will be available in the library i can create a new version of the run i can rename those slots this one is using the run animation this one too but i can modify the way they use the different animation so i will rename all of my actions so that it looks a bit better and when i will click the apply button i will see my library under my fbx updating tool from there let's see the modification we can add to any of the animation i will start by selecting the run animation and go down we can see that the animation goes from frame 0 to frame 16 i can change this and stop the animation before frame 16. so you can absolutely add a new animation to your library that will only use the part of the animation you have imported as you will do using dnla editor in blender by default animation are played in loop in the preview but they won't be used as loop if you don't specify it so for any run cycle idle just enable the loop time option the cycle offset option allows you to start from a different frame than frame 0. the loop pose option will force unity to try to smoothly blend between the first and the very last frame of your animation if your animation is already a perfect loop you won't see any difference but if i cut the run cycle in half and apply this loop pose you will see that unity is trying to blend to create a smooth cycle you can change the speed of the preview using this controller here regarding the additive reference pose i have absolutely no idea what it is made for the curve option is pretty interesting i will use the idle animation then i can add a curve input to this animation that will play along with the animation so it won't be currently affecting our animation it's just a new input and we can use this input for whatever we want it could be then use in the code to drive the emission shader of fire for example or i can make a s curve and say this is the briefing motion of my character and the higher the curve to more smoke or foggy particles will be blown by my character you can create event upon your animation and those events will be read each time you play the animation and reach their frame then you can tell those events to trigger a sound for example during an attack or an fix or whatever you are able to code with it the motion option allows you to choose what bone you want to use as a root shambo so i will just select the couple of animation that need to loop on my character and enable the loop time and don't forget to apply any changes to the fps to be able to use the animation library we've just set we need we need to create an animator controller then when i select my character in the scene i can see that it already has an animator component that is empty so i can drag and drop the controller i've just created now i can open the animator window and i can go into my fbx library and drop the idle animation the idle animation node will appear as orange meaning that it's the default animation and when i play the scene i will see my character playing the idle animation and the idle animation will be looping as we have set a looped time option into the fb you can change any animation in a node by dropping a new animation in the motion slot as you can see here the animation stopped because this version of the idle wasn't set to be a loop i can fix it by going back into the fbx and enabling the loop time and apply i will add a new animation the run animation right click onto the idle and make a transition to the run animation when i launch the scene i will see my character transitioning from the idle pose to the run cycle automatically and this is because we haven't set any condition to the transition by default unity will set an exit time to a transition meaning that once it has played portion of the animation it will automatically switch to the next one here i'm telling unity to play 90 of the animation and then blend between the idle to the run cycle in 0.25 seconds you can change the blending value by moving those two handles the shorter in time the more abrupt will be the transition the longer the smoother but if you do it too long your character will be kind of floating in the air so here i'd like to have the control when i want my character to run i want to create a condition or an event that will be called by the developer when the character is supposed to be running so i will uncheck the as exit time option meaning that we are not playing the first animation and when it's finished with transitioning but we are using a condition but as i do it unity will warn me that it need a transition parameter and when i try to add one it told me that there is no parameter so i will stop the player and add a new parameter and choose trigger i won't be going through all the parameters because this is something you should do with your developer what kind of behavior what kind of event do they want to use to trigger an animation i will use a trigger and set its name to run because it's the simplest parameter when you enable it it trigger an action with the trigger created i can now use it as a condition for my transition if i now play my scene the idle animation is looping and as soon as i click on the trigger it will enable the run cycle now i need to create a new transition from the run animation to the idle and create a trigger so i will create a new trigger that i will call idle and i will set it as i have set the run trigger now i can switch from one animation to the other for the attack animation i just drop my attack animation in the animator i've created a new trigger called attack and made a transition from idle to attack but to get back into the idle i don't need a trigger i can use the exit time as soon as the attack animation is done it will get back to idle automatically now you may sometimes want to achieve more complex animation for example a simple jump where your character will be on the ground and jumping then it will be hairborne and finally will land in this case i have a free animation a takeoff animation that i will enable using a jump trigger this takeoff will automatically transition into a jump loop animation using the exit time and this animation is supposed to transition into a landing animation that will also then transition into the idle but instead of using a specific trigger to go from the jump loop to the jump landing animation that i will call japan jump lane for example and then go back to the idle i will simply use the idle trigger to go from the jump loop to the jump plane and then from the jump lamp to the idle i will simply use the exit time this way using the same trigger as for the run i can tell the development team whenever you want to stop an emotion call the idle trigger and instead of recreating the setting of the idle transition i can go on to the existing transition between the run and the idle right click on the transition option and copy the transition parameter then go on to jump loop transition right click and choose whether i want to pass the condition the settings or both [Music] now what if you want to create a transition that can start from any other animation let's say i want to add a hit animation that will interrupt the run the attack the idle whatever instead of creating a transition between each animation toward the heat animation i can use the any state box and basically mean whatever the animation i'm playing whenever i'm using the hit trigger launch the hit animation and once the heat animation is finished if i want to return to the idle i can choose to use the exit box it will redirect my animation flow directly to the entry and since the entry is connected to the idle it will transition directly to the idle i can then do the same with the depth animation import the depth animation create a depth trigger and make the transition between the any state box and the depth animation so whatever the state of my character if the death button or trigger is hit my character will die and unless there is any resurrect mechanism in your game i don't need to make a transition from the death animation to any other state upon this dramatical event i will call this video finished i hope you've liked it and i hope to see you in the next one cheers
Info
Channel: Pierrick Picaut
Views: 36,863
Rating: undefined out of 5
Keywords: blender3D, modeling, shading, rigging, B3D, p2design, sculpting, digital, animation, cartooning, rendering, CYCLES, tutorial, Pierrick, Picaut, Pieriko, 3D, Computer, Graphic, blender, eevee, VIDEO GAME
Id: QRJ4OnTAaE8
Channel Id: undefined
Length: 23min 49sec (1429 seconds)
Published: Mon Nov 16 2020
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.