How to Animate Characters in Unity 3D | Animation Retargeting Explained

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
Hi, I’m Nicky! Welcome to my Channel about Game Development. This is a video in a series dedicated to learning Unity’s animation system. In the previous video, we learned to give players control over character animations using two dimensional blend trees. Today we are going to learn how we can retarget animations from one character to another! Alright, let’s get started! At the start of this series, we learned to download free characters and animations from a free adobe platform called Mixamo. We proceeded by learning to import, set up, and control them in Unity! Let’s rewind back to our starting point. We’ll start by downloading a single jumping animation from Mixamo with the usual settings, except this time we’ll add the skin and export a different character than the one that we initially downloaded. If you are new to the series, any character will do and feel free to use the settings on screen. Opening Unity, we’ll import this new character and animation. Next, we’ll open up the asset store and download and import two free additional characters: Jammo, which is the free mascot character of the youtube channel “MixAndJam”. And “SpaceRobotKyle”, which is a classic free character provided by Unity for download. In newer versions of Unity, we can download and import these characters from the package manager. When importing Jammo, we’ll need to be sure to deselect unnecessary folders. We really only need the materials, Models, and Texture. Now to get everyone starting from the same place, let’s start by adding Jammo, SpaceRobotKyle and our new Mixamo character to the project hierarchy. If our projects are URP or HDRP, we will need to upgrade the materials of our characters by pressing edit, render pipeline, universal render pipeline, upgrade project materials to UniversalRP Materials. Additionally, our mixamo character may have textures packed in the FBX file. To extract these materials, simply select the character from the project tab, press Materials in the inspector and click Extract Textures. Next, We’ll add animator components to each, create a new animator controller titled “retargetController” and select this controller using the circle selector. If you are starting from previous videos in the series, you may have the original mixamo character from previous tutorials. For this character, we can remove the old animation controller, disable any scripts and reuse the “retargetController”. Great! Now let’s begin by demonstrating how the jump animation we just downloaded is not currently compatible with any of our characters outside of the original character it’s attached to. Duplicating the animation, we’ll rename the copy to testJump. Next we’ll add the animation to our retargetController as a new animation state and set testJump as the default animation state. Entering play mode, we’ll see that our new Mixamo character performs the jump, but the others don’t. But why? To get a better understanding, we can take a look at the animation itself. If we open the animation tab, we’ll be presented with… nothing. This is because we need to select either the animation from our project tab or we can just select the characters in the hierarchy. Let’s select the working Mixamo character, and we’ll immediately see the animation tab be populated with new data. In the left panel, we’ll see all of the bones that are modified in the animation and in the right panel we’ll see the keyframes. Each key stores the changed parameter values per bone for every frame. If we press on the preview button and press play, we’ll see that the Mixamo character performs the animation! Great! Everything works as expected. Now let’s select any of the other characters. We’ll find that this animation currently is incompatible with any other character. This is because the bones of our original character do not match the bones that are modified in the animation. When looking at the bones in the animation, Unity will tell us that each bone is “Missing”. And if we want to be specific, we will notice the difference in this particular example is that the bones in the new animation all have different names. So can we simply rename all of the bones in our selected character’s rig in order to use the animation? Well this might work if the bone positions are fairly similar between the characters. But if the character models have different proportions, we end up with an unusable result like this. So what can we do to fix this? How can we share animations between models that are seemingly very different? The answer is Unity’s avatar system and humanoid rigs. We’ll start by selecting our imported character in the project tab. In the inspector window, we’ll see four tabs: Model, Rig, Animation and Materials. For today, we’ll just be using the “Rig” tab. Selecting “Rig”, we’ll be presented with new settings: “Animation Type”, “Avatar Definition” and “Skin Weights”. Let’s start from the top. We’ll notice when selecting the “Animation Type” drop down, we have 4 options: “None”, “Legacy”, “Generic” and “Humanoid”. Selecting “None” will actually disable the character’s rig, so it won’t animate at all. “Legacy” is Unity’s original animation system from years ago prior to their purchase of Mecanim: which is the backbone Unity’s current animation system. Unity’s documentation states not to use legacy and that it’s simply there to support old projects that were already using that animation system. “Generic” is what we’ve been using in this series up to this point. It’s the default Animation Type when importing character fbx files from Mixamo and Blender that include character rigs. And finally, we have Humanoid, which is Mecanim’s solution for retargeting animations between “humanoid” characters. Typically, we might think of humanoids as bipedal characters like humans, orcs elves, robots and aliens. Let’s select humanoid. we’ll notice that the “Avatar Definition” setting is now set to “Create From This Model” and a new “Configure” button is greyed out. This is one of the two selectable options: the other being “Copy From Avatar”. These being the only two options, we now understand that avatars are required for Humanoid Rigs. Pressing “Apply” we’ll see “Configure” is now selectable. This will take us to a completely new menu within Unity so before we press it, let’s cover the remaining settings. Skin weights are used to modify the vertices of a mesh on a per-bone basis. In a 3D modeling software like Blender, we are able to perform a process called “Weight Painting” where we designate which bones will adjust selected vertices when the bone moves. When weight painting, we can have multiple bones impact a single vertice. For example, if we really wanted to, we could have the toe bones control the head of our character. So taking this back to Unity, “Skin Weights” has a default value of 4 bones which can control the vertices of the character mesh. but can also be set to a custom amount if our model has vertices that are impacted by more or less than 4 bones. Additionally, when custom is selected, we can give it a minimum accepted influence amount so that bones that have less than a certain percentage of control over the vertices won’t be included. Unity’s default value of 4 bones is to enhance performance, so it is possible that if certain bones are neglected, a model may deform in unexpected ways. Here are a couple of examples from the Unity forums where developer’s meshes were deforming differently than they did in the modeling software. Today we’re going to stick with the default value of 4. And the last setting in this window is the “Optimize Game Object” toggle which is another setting that appeared when switching to humanoid. This will remove the transform hierarchy from the imported model and essentially bake it into the avatar and animator component. It’s recommended in the docs to apply this before shipping the final product, but I did notice that if we have an animator component already attached to our character in the scene hierarchy, our character will disappear. Be sure to apply this setting without an animator attached or you will need to remove the character and add the prefab back to the scene. For now, we will leave the optimization unchecked. Awesome! We now have a solid understanding of all of the Rig settings. Pressing “Configure” we’ll see a completely new menu in the inspector and our scene view transforms into an isolated view of our character. In the inspector, we’ll be presented with an outline of a humanoid character with small circles at designated parts of the body. And below, we’ll see a list of body parts associated with each circle. The dotted circles are considered optional. When first configured, Unity will attempt to auto-map each bone from the character rig to its corresponding bone in the list by searching for specific names and abbreviations that match. When using characters from Mixamo or one of the many humanoid characters downloadable from the Unity asset store, it’s more than likely that the auto-population will have each matching bone properly sorted when first entering this screen. This is why the list is already filled out! However, if we make our own characters in a 3D modeling software such as blender and have different names for our bones than what Unity is expecting, we’ll instead be presented with a red character outline. And the list will have empty selectors that we’ll have to go through and map ourselves. For more complex characters and animations, we also have the options to map bones associated with the head, and both left and right hand. All of which are optional. At the bottom of the list, we’ll see two dropdown menus titled “Mapping” and “Pose”. Mapping has 4 options: “Clear”, “Automap”, “Load” and “Save”. Clear will remove all paired bones. And automap will search through the list and pair associated bones found in the character rig; the same function that is performed when we first configure the humanoid avatar. Again, this only works if Unity can find the bones by name. Load and save allow us to save and reuse our list of mapped bones. This would be useful in situations where the automap failed, and after we finished manually mapping the bones on one character, we could save and then load that mapping for other characters with the same bone names. The pose dropdown has just 3 options: “reset”, “sample bind pose” and “enforce t-pose”. When the humanoid is first configured, if the automapping of the bones works as intended, Unity will automatically apply “enforce T Pose”, which is what we see here. If we press “reset”, the character will shift its bone transformations back to the starting frame of the animation attached to the character, or the rest pose if the character doesn’t include any animations. And lastly, “sample bind pose” will reset the character’s bone positions back to the character’s bind position. The bind position is the position the character mesh was in when initially binding, or connecting, the bones to the mesh. The binding process is done inside of a 3D modeling software and the bind pose is hidden and stored in the FBX file. Any changes we make in this menu will need to be applied before pressing Done to exit out of the avatar configuration process. Before we move on, we have a second tab titled “Muscle and Settings”. This menu is for modifying the muscle constraints our character currently has. We can preview these constraints and how they impact the possible range of motions for our character by moving the sliders around in each column and row. If we want to adjust the constraints, we would do so in the Per-Muscle Settings and Additional Settings and press “Apply”. The muscle settings are typically used when converting models from generic to humanoid that have exaggerated character meshes. For example, a character with massive arms might experience clipping where a smaller character would not. We can adjust the constraints of the muscles to limit the bend in the arms and reduce any visual issues! Ok! Now that we’ve completed a breakdown of Unity’s humanoid rig setup, how does this help us? The answer is quite simple: when we convert the character to humanoid, this process generates a humanoid “avatar” storing the new bone hierarchy that is interchangeable with other humanoid avatars! It also converts any animations that are included in the character FBX file from generic to humanoid meaning any humanoid character will be able to use this animation! Let’s go ahead and create humanoid avatars for all of the newly downloaded characters. Once completed, we’ll select each of our characters in the hierarchy, and using the circle selector in our animator component, we’ll match the newly created and corresponding avatar! Pressing play, we’ll now see some possibly unexpected results. Now none of our characters are jumping. This is because we duplicated the jump animation before we switched to humanoid rigs so that animation is still tied to the old bone hierarchy! So the last change we’ll need to make is to duplicate the animation one more time from the now humanoid version of our mixamo character. This time we’ll call it “retargetJump”. We’ll delete the “testJump” and set “retargetJump” as the default animation state. Pressing play and Vwalaha! We have retargeted our jump animations from one character to another! Amazing Job! With what we just learned, a slight modification to the scene, and a brand new animation: we can get an awesome result like this! Before we end today, there are a couple of important notes. To start, if we download animations from Mixamo without the skin, we still can and need to switch the Rig type to humanoid. When downloading these animations on mixamo, be sure to have the same character selected as the one you used from this tutorial. This way, the animation FBX will have the same bone names. AND we also need to select copy from avatar and select our downloaded mixamo character’s avatar! Now these new animations will be usable with our other characters Next, if you have been following along through this series from the very beginning, you will need to switch the Rig type on all of the animations in your animation states to humanoid if you want them to work with humanoid characters. If any animation in our animator have generic animations, it will break the character’s animations. I recommend renaming the new humanoid copies of the animations to avoid confusion. And when selecting the duplicate animations we also want to change the “Root Transform Rotation” setting from “Body Orientation” to “Original” and check bake into pose for our animations to look as expected. Lastly, if you are completely new to the series, in previous videos we learned to control animations through player input. With the knowledge attained today about humanoid characters, we can combine that with the teachings of previous videos and actually give players control over any of our humanoid characters and animations! It’s RAD! Awesome work today! If you liked what you learned, please consider pressing the like button and subscribing to the channel! It really helps the channel grow and tells me that we’re covering content you care about! In the next video, we’ll learn to use animation state layers and not long after, animation based events! If you would like to join a growing community, I’d be happy to have you as a member of the channel discord! Link is in the description. But that’s all for today, thank you so much for watching and I’ll see you in the next video!
Info
Channel: iHeartGameDev
Views: 50,449
Rating: undefined out of 5
Keywords: How to Animate Characters in Unity 3D | Animation Retargeting Explained, how to animate characters in unity, animate in unity, character animations unity, unity character animations, player controlled animations, nicky b, share animations unity, humanoid animations unity, humanoid unity, humanoid rig unity, share character animations unity, animation retargeting unity, animation tutorial unity, animate characters unity, character tutorial unity, game development for beginners
Id: BEZHVYk6Fa4
Channel Id: undefined
Length: 15min 1sec (901 seconds)
Published: Sun Sep 20 2020
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.