Advanced techniques of working with bone-based 2D characters | Vladimir Limarchenko | Skillshare

Playback Speed

  • 0.5x
  • 1x (Normal)
  • 1.25x
  • 1.5x
  • 2x

Advanced techniques of working with bone-based 2D characters

teacher avatar Vladimir Limarchenko, Game Developer, Unity3d and C#

Watch this class and thousands more

Get unlimited access to every class
Taught by industry leaders & working professionals
Topics include illustration, design, photography, and more

Watch this class and thousands more

Get unlimited access to every class
Taught by industry leaders & working professionals
Topics include illustration, design, photography, and more

Lessons in This Class

11 Lessons (2h 5m)
    • 1. Introduction

    • 2. Making a Bone based Animated Character

    • 3. Resolving Sorting Order Issues

    • 4. Sorting Order Fix Script Part 1

    • 5. Sorting Order Fix Script = Part 2

    • 6. Scriptable Object Assets in Unity

    • 7. Applying Outfit from Asset

    • 8. 108 Outfit Applier Script Basics

    • 9. Displaying Unique Items

    • 10. Character With Joints Part 1

    • 11. Character With Joints Part 2

  • --
  • Beginner level
  • Intermediate level
  • Advanced level
  • All levels
  • Beg/Int level
  • Int/Adv level

Community Generated

The level is determined by a majority opinion of students who have reviewed this class. The teacher's recommendation is shown until at least 5 student responses are collected.





About This Class

Making a 2D platformer game is a nice way to start learning about Unity game development. In this class we`ll cover some of the advanced techniques of working with so-called “bone-based” 2D characters - characters that are made out of separate body parts. We`ll start off the tutorial with a pre-assembled simple bone based character and we`ll focus on these topics:

  • Resolving all the sorting order issues when you have multiple bone-based characters in your scene.
  • Creating ScriptableObject assets in Unity to store data about your character`s outfits.
  • Applying different looks to your character from ScriptableObject assets.
  • Displaying extra outfit items like bracelets, necklaces, belts, clothing items to decorate your character.
  • The concept of “joints” that will let you describe characters that are shaped differently with the same animated model. For example: one character might have shorter legs; another might have wider shoulders and they`ll still both be made out of the same prefab in your project.

This course provides a complete guide on making and managing 2d bone-based characters in your Unity project. It is very beginner-friendly and I try to explain everything that I am doing as much as I can.

Additional information:

  • The files showed in the course are downloadable from the link that you can find in the "Class Project".

Meet Your Teacher

Teacher Profile Image

Vladimir Limarchenko

Game Developer, Unity3d and C#


I am a Unity3d and C# developer with about 2,5 years of experience in game development. I also have a scientific background. I got a Ph.D. in Theoretical Mechanics in 2014, but then decided to pursue my childhood dream of becoming a game developer. I'm mostly interested in making 2D games. In my opinion, a perfect game should have some tactical or puzzle element to it.

Over the last couple of years I've also worked as an instructor and created several courses on game development. Some of the topics of my courses are: making a 2048 game, building quiz apps, creating a simple virtual pet game, animating 2d characters, building an in-game character customization system.

I'm always willing to experiment and work on some interesting and challenging game mechanics.

See full profile

Class Ratings

Expectations Met?
  • Exceeded!
  • Yes
  • Somewhat
  • Not really
Reviews Archive

In October 2018, we updated our review system to improve the way we collect feedback. Below are the reviews written before that update.

Why Join Skillshare?

Take award-winning Skillshare Original Classes

Each class has short lessons, hands-on projects

Your membership supports Skillshare teachers

Learn From Anywhere

Take classes on the go with the Skillshare app. Stream or download to watch on the plane, the subway, or wherever you learn best.


1. Introduction: Hello, everyone and welcome to the scores about some advanced techniques off working with bone based duty characters and by saying bone based characters, I mean the characters that are organized out off all these separate body parts. For example, if we explore how this character is made in hierarchy, you can see that he has a separate torso game. Object Neck had eyebrows. So these game objects, the old, are organized in a certain way in hierarchy and this way to any major character. You just move all these body parts relative to each other. We have two characters in our scene, and now they look very similar. The first stopping that will discuss in this course is sorting order. When you have several bone based characters in your scene and in your project, when they walk on top of each other, they might interlacing a number off weird ways. So first will discuss how to avoid this situation with different body parts off your characters, interlacing and not behaving the way you want. And the second thing that will discuss is applying custom. Look to your characters so you make one game object, one prefab off your character and then you can make it look, however you like. We'll talk about script, herbal object assets that are very convenient to organize all the info about your character that defines how he look in the scene. And one more thing. I wrote one little extra script just to keep you interested in this project and show you the possibilities that it opens up for you. So now if I launch the game first, both of these characters they will look differently different from what we had in our scene , and they will have different outfits applied to them. We can control this character, and the 2nd 1 is an NPC character so we can just walk on top of him. You can also make this NBC character appear on top of your character sorting wise. So you have all these different interesting possibilities. Our character can jump onto this improvised platform. So one of the topics that is covered in this course is applying thes different outfits to your characters, and this technique empowers you to do a lot of different great things with your characters . For example, I have a simple script on this moving character that works like this. If I press let her s on my keyboard, he will shape, shift and turn into a different character. And internally, he just applies a different outfit asset or a different outfit to himself. So I can even walk and shape shift while walking. And you can figure out a game with a cool mechanic that uses this approach off, changing how your character looks and how he behaves in the scene. And another thing that is really subtle here. And it might be hard to notice our character with the green skirt, the one that we're controlling. Right now. He has a bit wider shoulders, so we'll also cover a really cool way off managing your characters that use the same animated model. So you animate your character just once, And then you can make differently shaped characters with wider shoulders, shorter legs, longer legs and so on and so forth. And all the animation work, all the scripting work. It only has to be done once. So now if I shape shift again if I press s this character is a bit thinner and his shoulders are a bit smolder. If I press s began, you'll be able to notice the difference. Our character with the green skirt has wider shoulders. So you will learn all these advanced techniques off working with your duty bone based characters in this course. Thanks for watching the intro, and I'm excited to see you in the next lecture of this course. 2. Making a Bone based Animated Character: Hello, everyone. And thanks a lot for watching this course about all the advanced stuff that you can do with your two D characters, your bone based duty characters and so on. So the material that will discuss here is a bit more complicated. That's why we have to start somewhere. So we were not making everything from scratch. Instead, we'll start with this character that is already pre made, and in this video I'll make an attempt to explain how this character works in general, in case if you haven't seen some of the previous content that I've made, where I explained how to make this exact character. So first off, my game is running and let's check out what our character can do so we can walk around in the scene and he'll play this walk animation. And another function of this character is he can jump so our character can jump and he can jump onto this little improvised platform that I've added to the scene. I know that it doesn't match 100% but I added it just for the sake of demonstration that he can jump. And the interesting part about this character is how he's made and how he's assembled. So this character, he actually consists out of different body parts. So, for example, here is the game object that represents our character in the hierarchy. And it has all these different child objects, the torso, the neck of had off our character. And they're all organized in this certain weight or order, and also they can move relative to each other, for example, that or so we can rotate the torso and it will lead to rotation off his arms and his head as well. And the legs are organized in a similar manner so we can rotate this lack, for example, and this way will make our character walk. Now, to make a character like this, you have to go through certain steps. So the first step is importing the art into your project. In our case, art is represented by these three different images, and they look like this. So the first image looks like this. There is the second image, and there's this third image, the one that we use for our character on. All of these images were interested in this part the one way the separate body parts. Once you have imported the sprites into your project, you have to follow these steps First, the sprites, when they are imported, you will most likely get the Sprite mold single selected here. Anyone to make sure that you select multiples. So we want to cut out multiple images out of thes sprites. Once you do that, you can go to the Sprite editor. And a Sprite editor is a tool that will let you slice all these sprites and get these individual images off different body parts out of them. So to slice your sprite, you have to go to this little drop down menu and just breast slice. Now, once you do that, you will get all the sprites that are present on this image, including the letters in this walk words. And, ah, all these individual frames that represent animation frames off your character. You will get all of them sliced and ready for use. Another thing, we don't need all of them. So we're not interested in thes individual animation frames. So the next piece of work is deleting all the sprites that you don't need now to delete something. You can just select a sprite like this and hit delete on your keyboard. This will raise this sprite and you will only be left with what you truly need. Now, in your case, after you do this, you have to press apply. In my case, l pressed Revert because I don't want to make any changes to this sprite for now. And another important step off making your character is setting up the pivot points and the pivot points there, These little round points in the center off your sprite they will mostly beer in the center , by default and for our body parts, we want to set them a bit differently. Now, the logic here is this, for example, this upper part of the arm off our character. It will be attached to the torso and we wanted to rotate around this point. So we want to set the pivot points to the points where this body part attaches to a bigger body part that is closer to the tour. So, for example, for this lower part of the arm, the pivot point is set into this corner points, so it will be attached here to the upper part of the arm and the same is true with our neck . So the neck will be attached. Do the tour. So in this lower point that had will be attached to the neck here. So you have to set up all these pivot points and then you should hit Apply now, After you do this, you'll have all these individuals, sprites, cutouts and ready for use in your project. And then you can simply drag them into your scene and start assembling your character. And there are several steps in this process. So let us illustrate this on this store so and the arm. First, you have to get the parenting right so you can see an example off the character that we already have in the scene. His top closer hand is a child game object of the torso so we can do the same here who make this upper part of the hand the child of the tour. So and this lower part of the hand should be a child of the upper part of the hand. This way, when we try to rotate the upper part of the hand, the lower part of the hand who moved together with it and If we try to retake the lower part of the hand this point, it will behave like like an elbow joint for this character so we can control the exact blazing off this game object about the parenting. We've already got it right. Then there is another important step in setting up your character, which is setting up the sorting order. Now we don't see any sorting order issues, but if I add another arm, for example, this one, we want this arm to appear behind the torso, and it currently appears in front of the torso. Now, to control this, you can change the order in layer on this sprite. Render off this part of the arm. So for the order in layer, I suggest to use bigger values. Don't just say minus one, and it fixes your problem, and that's it. Sometimes you might want to fit something in between your torso and your arm. For example, a sleeve for your arm if your character will be wearing a shirt later, so don't just say minus one. Instead, use big steps. Say something like minus 20 here, and you have to go over all the different body parts and set up the order in layer for them in a similar manner. And I'll just delete this character for now because we have a more advanced and more ready character that he's already set up. So let's take a look at that on this character. What I would suggest is create several empty game objects just for the sake off organization so we could have made the tour so represent our character, and we just attach all the scripts to the store. So game object. But I found that it is not very nice approach, so I create several empty game objects that might help me later for different reasons. For example, this game object that is called a front view is just an empty game object, and you can create one by right clicking in the hierarchy and saying, Create empty. You can rename all the game objects so that they have their descriptive names now returning to empty game objects. This center of Mass is also a completely empty game object, and who knows? We might need it later for some reason. So let's just have it, and the last game object that we have here is the character name object. The next step, when you have your character set up correctly in the hierarchy and in terms of sorting order, is animating your character when your character has no animations and you switch to this animation tab. Now, in case if you don't have it, you can simply open it by going to window animation. You'll just have a bottom that is called create here for creating a new animation. When you already have some animations on your character, you can add new animations by going to this drop down menu and selecting Create Nuclear Pierre. First animation that I have created is this Idol animation that has absolutely nothing. So I've just created this animation, and when this animation is played, our character will just look like this so he will not do anything. The second animation that I created is this walk animation. When I hit play, it looks like this, so the way off editing the animation. If you see this little red button pressed, it means that you are in recording mode, and if you're moving something here on your character, it is getting recorded and saved into your animation. Now the way to any made this character. You should find some reference material with the walk cycle on the Internet and try to recreate that by mostly controlling the rotation off your game objects. So here's the rotation for the top closer lag that is changing throughout the course off this animation, lower closer lag. So mostly you control the rotation off all these game objects to achieve the fact that you want and for the front view game object were also changing its position. So here wants the animation displayed. You can see the position changed, and it is also part of the walk cycle, and this way it looks more sort of natural. You can later refine and enhance this animation, so it is not set in stone. The most important part is that you just have it. And once you have your animations, one interesting thing happens. So to make sure that I'm not making any changes to my current animation, I have to uncheck this Baden. It means that I am no longer editing the animation, and I'm not making any changes to it, and any mates or component will automatically be added to our character. Let's go to the any major tab and see what's in there. So the animator component is used to transition between all these animations that our character has. He has idle animations that means just don't do anything. He has the walk animation that we have just seen. And he also has this interesting state in his any major component that is called Not Grounded and the Snow Ground. That state is actually called a blend tree. So if we double click on, the state will sort of enter inside of this blunt tree. And the purpose of the blend tree is too show different animations on our character based on a certain parameter. In our case, we'll show different animations based on his vertical speed, the vertical speed stents for fulling, jumping, climbing ladders and all the other movements that your player can make in a vertical direction and to make our character able to jump. I've also created these seven different jump animations, these three initial animations. They're more like jump stage or beginning to jump. This animation number four is the highest state off our character, so let's go back to the scene and check out how they look. So the 1st 1 looks like this. The 2nd 1 the 3rd 1 the 4th 1 And then from here we start falling the fifth, the six and the seventh. And we'll just show these animations depending on our V speed parameter that we have also added to our any maser. Now I know that there's a lot of stuff to take in, so just play around with this animates or component and see how it's set up. It has only three different parameters. And let's just leave the animator for now. So we have the animator returned to the base layer. It has all these transitions that are also set up in a certain way to ensure that we can transition from any state into any other state. That is also important. And finally, let's check out how we actually move our character. So I'll press this little red mark here to make sure that I am not editing the animation. I will select the character and we also have several other components other than any major attached to our character. So the first script is cold controller. Now this script is custom made by myself. It is a very simple controller script that moves the character using his Regent body duty component. Now the rigid body is part of the built in physics package that is present in unity. To add new components to your character, you can just press on this button at component and Search here, for example, rigid body duty. When you press enter, the rigid body component will be added to your character. There's not a lot of configuring that you have to do on this character. You have to set an appropriate gravity scale. In our case, it's 15 and you have to freeze rotation in that excess. It means that your character should not full over into either one of these sites. And next we should also attach to D colliders to our character. In our case, we use to colliders and because of the background, your note. You're probably not able to see them, so I'll go back to our character. We use a circular collider at the feet off our character and a rectangular box glider for the top off our character. You can attach colliders theory character in the same way. Just search for books, glider duty or Circle Clyde or duty in this menu and just hit. Enter and then you can also edit these gliders so you can use these little squares to change the dimensions and the area occupied by your collider. Al just press controls that undo the changes. So more or less this is how this character works and how he's set up. If you have any questions about this character and about the process off making him, please feel free to ask them. And I'll try to answer all of them. Just a quick reminder. I made some more content related to duty characters, and there must be course. Or you might be getting that content together with this course. I don't know how exactly we would be presented. There is a detailed course that I have made that describes this whole process off, creating this character up to the point where we are right now. So in our next videos will discuss some more advanced stuff that we can do with this character. The stuff that will be covered in this course is re skinning our characters. So, using one model or one game object that is called character and applying different looks. So our character, this same character, he can also look like this. Or, for example, like that second character that we have here like this. So that will be one of the topics and also resolving all the different issues. When we'll have several characters in our seen, it will all be covered in our next videos. So thanks a lot for watching and I'll see you in the next video. 3. Resolving Sorting Order Issues: Hello, everyone, and thanks a lot for watching the scores about some advanced techniques off working with duty characters. So in the previous video I described in general, the steps off setting up this character and in this lecture will talk about some of the first challenge is that this project and two D characters may present us with. So currently we have just this one character in the scene, and it is our main character, the character that our players control. But what if we wanted to have another character that it's similar to this one in the scene as well? For example, that character might represent an NPC so unknown, non player character that we can maybe have a conversation with. He can give us a quest, but he will look absolutely similar. Or he will look like one off our other characters that we have here in our art assets. So, first in the previous lecture, I've disabled the background. Let's enable the background back and let's just dry, adding another character. Now this character is saved as a prefab in the project. So one way off adding this character to the scene is just by dragging it from our prefects folder right into the scene. This way, we'll have two of them. Another way of doing this I'll just delete this character for now, is selecting our already existing character and pressing control D on your keyboard. This way you create a copy off a character that you already have, and I can just bring it to the side and we'll have two of them this way. First, let us start the game and check out how this works. So when I press play, when we start the game, both characters fall to the ground. And when we try to control them with the keys on our keyboard, they both walk in the scene, which is not exactly what we want. So we want one of the characters to stay still, and we want to control on Lee the 2nd 1 So the way to achieve this is I've made several changes to our controller script, and the main change is this. Check Mark can control this character, so when this is checked, it means that this character and this controller script will listen to the input from our players. And if we try to uncheck it, then the script will no longer listen to any input whatsoever. And now, if I launched the game, both of the characters full onto the ground, and now we are only able to control this one character. But instantly there is another challenge. So if I go with this character and they try to interact with the character of that is just idle, that is just standing. So our NPC character, then you see that they interlaced in this weird way. So this is not exactly what we want to achieve in terms of sorting. And what's happening is this. We have exactly identical sorting order on all the body parts on both of these characters. So when we walk with one character on top of the other, it means that since the body parts have the same sorting order, these two characters, they sort of inter lace, and we have to find some way to separate them and to make one character appear entirely on top of the other or behind the other character. So one way of doing this, and it's an easy way of doing this is just by controlling the sort engl a er so for this character, one that we have in our seen alcohol, this one NBC temp because we'll have another prefab for our NPC characters later. But for now, we can call him NPC temp, and I can create a prefab out of him. This way will ensure that if I accidentally hit apply here thes changes, they will not apply to our regional character. And the easiest way to resolve this conflict is by changing the sorting layer. So one way of controlling the sorting is the sorting order, which is just a number, and the second way of controlling this is sorting layer. So let's go on and find one of the sprites on this character, for example, list or so is a sprite. The sorting layer is set to default. So is the sorting layer on this character. So if we select the tour so for our main character sorting layer is set to default here as well. And for this NPC temp, we can change the sorting layer off hissed or so and all the other body parts with sprites as well. For now, we can go to sorting Lear slag, this option at sorting layer and for now. In our project, we have just these two sorting layers, the default layer and the background. Let us add another sorting layer. For example, I'll add sorting Layer. NBC's here and out pressed Enter. We can move these layers around, and we can make our NBC's appear on top off our default layer or behind our default layer. Let's try to rearrange layers and make the NBC's appear behind our character. So this way I'll just expand all these transforms or all these game objects, and I'll select only those that have some graphical representation in our scene. So I'll select the torso. Hold shift. L select all of the's game objects, and the legs is actually an empty game object. It doesn't have any Sprite render. So when I d select the legs, we can select the sorting order for all these sprites and let us set the sorting order to NBC's. I forgot one more thing that is very important. I had to expand the head, and we also have these game objects for eyebrows, eyes and mouth, and we should also apply this sorting layer. NBC's to them. So once they do that, I'll apply the changes to our prefab again. And now if I launched the game, if I walk with this character on top off that standing one, the NPC will always remain behind our character, and that is exactly what we wanted to achieve here. So that is one way off. Doing this the second way is a bit more complicated, and it involves adding a custom script to our characters. So let's say you are making a multiplayer game and you want to have several instances off this character, prefab or several characters in your scene at once. So you're not 100% sure that it is an NPC and you want to have some other solution for sorting your characters. And this might be achieved by adding a custom script to your character. So we'll do that. Let's go to assets Scripts. And I brought in this new script into our project that is called the sorting order Fix. Actually, for the sake of demonstration, let's change a couple of things. I will go to assets brief APs, and I'll rename this NPC temp to NPC sorting layer. So for this character, we control this sorting using sorting layers and I will create a copy of this NPC. So I'll just duplicate this repressing control de in the scene, and I'll call this new NBC NBC script sorting for this NPC. We want it to remain on the default layer. So if you have a situation when you want to have both of these characters on the same layer , and still you don't want them to inter lace like you. So with these characters previously, so we want to select all the sprites that we have so starting from the tourist. So I'll hold shift and I'll uncheck the legs. And I want to return this character onto our default layer for this NPC script sorting For now, it refers to this NPC sorting layer prefab, so we'll create a new prefab, and we'll attach our custom script from assets scripts, sorting order fix. I'll attach it to this NPC script. Sorting in this lecture will not need this NPC sorting layer so I can just deactivate this game object in the inspector, and it will mean that we only have our single NBC script sorting character. And there is this one check mark that says Add to sorting order. So the way this script will work and we can actually readjust it and maybe exposed some public fields in our next lecture the way it currently works, it will just find all the child Sprite renders on this character, and it will use an interesting technique to do this. But it will know about the torso, the neck that had eyebrows So it will find every single sprite render object that is present on this character, and it will add a large value to its sorting order. For example, if we add 1000 2 are sorting, order off each of these elements, so the eyebrows will now have a sorting order or an order in layer off 1000 and 30. This stop closer hand will have a sorting order off 1000 and 50 so a certain number will be added to our sorting order. And depending on this Jack mark, we can either add to sorting order or if this is uncheck, will subtract 1000 from our sorting order. So let's try that. Let's see at the sorting order is currently set to false and it's OK because we want to subtract and we want this character to appear behind our main character, so that's exactly what we want. And when a press supply launched the scene first we can walk around in the scene and you can see that the sorting is correct. So we're not interfering with this character in any way. And another thing that we can check. We can now check each off the sprite renders on our character. For example, let's dry the legs. So I also like this stop remote leg and currently it has this order in layer set to minus 1000 and 20. This eyebrows, they have the ordering layer minus 970. So because they had a positive value off sorting order, which was 30 now, we have sub directed 1000 and it means that we are now at minus 970. Now, if we exit play mode with these eyebrows selected, you can see that they will revert to their original order in layer value off 30. So this is another way off resolving the sorting order issues, and I think that the script that does this that is called the sorting order fix it is quite interesting so in our next video will take a look at this script and Mona Develop, and we'll discuss how it works. I would like to thank you for watching the scores and I'll see you in the next video. 4. Sorting Order Fix Script Part 1: Hello, everyone. And welcome back to this course. In our previous lecture, we have explored different ways off sorting our bone based character because they consist off all these separate body parts. Sorting might be an issue and there are two ways off Resolving this that we have inspected the first way is by changing the sorting layer on one of these characters, and this resolves the issue completely, and in some cases you don't want to use sorting layers just by design off your app. So these characters, they must be on the same layer. Then you can use another way of fixing this by adding some value to the sorting order off each body part. So for one character, you add 1000 for another character, you add 2000 and this way you ensure that they stand apart in your scene. So our go for this lecture is to explore the script, sorting order, fix and figure out how it works. I have already opened this script in Mona Develop and it isn't long. It is about 88 lines long, and we'll start our exploration of this glass not from the top, but from the bottom. We first have to understand how these two methods work, because these two methods they make the most important job in this script. The first method is private and it returns. The list off transforms, it is called get old child objects, and we need this method to get a reference to all those different body parts to the arms and the legs off our characters. And you might ask, Why are we not using this? We can also say, for example, get components in Children and transform into these parentheses. But this method that is built in into unity, it will only return the closest the immediate child objects off our character. And in our case, if we go back to unity for this NPC script sorting, it will return this game object itself that is called NPC script sorting. I mean the transform on this game object. It will also return the center of mass because it is a direct child off our NPC script sorting, and it will also return the transform on this ground check game object and that's it. So it will not care about the front view and old the tour, so the legs and we want to get them as well. So let's go back to our script and continue. We don't need this line. Get components in Children. So this simple method it will not work in our case. And another interesting thing is for getting all these transforms on our child Game objects were using a dupe while loop. So how often do you see a proper racial used for do while loop? So let's dive in and figure out what this gold actually does. So since this method returns, at least off transforms, we have to create one we say least transform. Old transforms equals new list of transforms. Currently, we just create an empty list that will hold transforms. And in the end of this method, we are returning this list so throughout this method will feel the list with some transformed variables, and then we'll be ready to return this list with all its contents. Then we create an integer variable that is gold count before and will use it in just a couple of flying's. And the next line says old transforms dot at and we are adding transform that is attached to this game object. So in our case, it will be a transformer off our game Object NPC script sorting and returning back to our script. And right after this the execution of the code goes into this do block of code. Now how the do while loop actually works all the code inside of this region after do it gets executed at least once. So without checking any extra statements, we just dive into this do part of the loop and we execute this gold once. Then after all, the code in do is executed, we check this statement after while if this statement is equal to true, then we continue our loop execution. And if the statement is equal to false, then it means that we have found all the transforms and we should no longer execute any code inside of this do block. And we just terminates our loop and we return our list. And the first line inside of this do loop is this count before equals old transforms count . So during our first execution, this old transforms count will be equal to one. So we'll see count before equals to one. And let us also check this condition that continues or terminates our loop. So if you want to continue executing this loop, it means that all transforms don't count should not be equal to count before. Which means that during this one, it's aeration. Off the loop, we were able to find at least one new transform, and now let's check out what the code in this loop does. So first we have a four loop, we say four, and I from zero eyes less than old transforms Count I plus plus. So it rates over all the transforms that we have in our old transforms list. And then for each of the transforms we're trying to search for child transforms. And we say, for each transform, child in old transforms with an index self, I. So for each transform that we already know and that we already have in our list, we're trying to discover its Children. And if our list all transforms doesn't contain this child that we have just found, then we should probably add it to the least. And we say old transforms add child, which is the most important. But another thing that we do while we it's race over this list. There's also another type off collection that you can use in C Sharp that is called a dictionary. In this class, we actually work with such a collection, and it's cold, old transforms by name. So let's scroll all the way up and check out how it's declared. We say Public dictionary and inside of these angle brackets, we have to now specify two types. The first type is string, and the second type is transform, and what a dictionary holds is a collection off a so called key value pairs. So our string here it is, the type off our keys and our transform is the type off our values. So will be able to access our transforms. So our values by our string keys. The dictionary is cold, old transforms by name. We're just making an empty dictionary here and inside off our method. Get old child objects. Generally, this should not be true. So this is just the check. And if we already have a game object with the same name, for example, you have one game object that is cold arm and another game object that is cold arm, so it's a bit of a sad back off this method that you have to name all the body parts differently. It will just return a debug Lok statement and it'll tell you the game object that has the same name. So all the names should be different and right after this line, it'll to say old transfers by name, ad child. So the transform that we have just discovered that has not being added to our list or through our dictionary dot game object dot name, which is a string and another coma. And here we are, adding the child itself. So the transform and this way will populate our list that is called old transforms. And also our dictionary that is called old transforms by name and will need this dictionary later to re skin our characters. So it is also very important, and the next method it is much simpler. It is also private and it returns the least off Sprite renders. So even when we have found all the transforms, not every single one off our game objects has a sprite render and we want to get all the sprite renders that we can find on those transforms to change their sorting order. So, in order to do this. Here's a similar method. It has a long name. It says Get old Sprite renderers from a transform list As an argument, we take your least off transforms that we can get from our previous method. And here we also create list off Sprite renders. It is an empty leased, and then, for each transform T in transforms. So the least, which is an argument of this method we say Sprite render S r equals t get components Sprite render. So we get the Sprite render that is attached to this transform or this game object. And if Sprite render is not equal to know, we might have a situation. When this transform doesn't have a sprite render, for example, our top most game object, they scold character or that is called an NPC. It has some streets animators, but he doesn't have a sprite render. Then we'll just ignore this game object, and only for those game objects that have Sprite renders will add the sprite render do this list Sprite renders found, and then this least is going to be returned from this method 5. Sorting Order Fix Script = Part 2: So now that we've gotten through these two methods, we have all the complicated stuff figured out. So let's scroll all the way up to see the top off our script. We have a Boolean flag that is called Add to Sorting Order, and if this value is true, it means that will add something to the sorting order. If the value is false, we'll subtract something from the sorting order and next line, it says. Static integer, render order offset and it is quite interesting. So this variable render order offset. It'll be static and it will be shared by all the objects that have our sorting order fix. It is used sort of as a counter off our objects. So the more we have off these different objects, the greater this value off render order offset will become. Then we have our private leased off transforms old Children, which is something that we get from the method that we just saw. Another private least private leased off Sprite renders that is called cold Sprite renders . And it's also something that we get from that second method, and we also have a private variable that is an integer and it is gold render offset used for this character. So sometimes in some situations you want to save this value that you used for this character. If you want to change the sorting order on all of his body parts and then return it back to the regional value, that's one of the scenarios where you might use this. So this value that you use for this character is saved. Then we have these two properties, and there it just used to access some of the private stuff that we have here. Public list of Sprite renders all sprites We can only get this. We can get all sprite renders, which is least here, and we also can get the render offset used for this character, which is just an integer just in case. If you want to change the sorting, order off all the body parts and then return them back to their original value, will not be doing this in this tutorial. But you might want to do it. Maybe in some scenario, in your games, when you want to move your character forward or move him back, that's when this property might be useful than in a Wake Wake. It's cold as soon as your scene is launched, and Unity advises that in awake we should get all the references and get all the stuff down . That has to be done before actually playing the game. So Khiry get all the child game objects by calling our method, and we signed this to our old Children list. We get all the Sprite renders from our list old Children. We use it as an argument in this method. Then there is this extra check. If our tag is equal to player than we just return, and what it means is, you can said this tag player to your game object. And it means that the sorting order will not be affected in any way. And it'll only work well if you have just one player in the scene. If you have several Blair's, then it will not go well, so you have to take this into account as well. Then we modify our static variable render order offset. So for each new game object that has this script in awake, method is cold. And for this game, object will add 1000 to our render order offset. Let's assume that awake on this game object is called first. Then we'll have render order offset at zero and will add 1000. Then if we are adding something to our sorting order, will say render offset used for this character en route Save the value plus render order offset else. If we are subtracting something from our sorting order will save the value off minus render offset. And lastly we'll just say apply offset which is our next method. And the office it is render offset used for this character. So the value that we have just saved If we have two objects in the scene with this script, so for the first object will add value off 1000 to our render order offset And it will be 1000 then And for the second object, this value render order offset will already be 1000 when the wake method is cold. So our resulting render offset used for this character will actually be 2000 or minus two Salvant if we are not adding to the sorting order. And finally this method apply offset, integer offset. We are iterating over all the sprite renders that this character has So for each sprite render s are in old Sprite renders. We are adding this value off offset to our s r dot sorting order and it's important to use the value off this render order offset That is at least one power greater than the highest sorting order that you use on your characters. So let's say even if you have a lot more body parts and the highest sorting order that you use is, let's say 500 something than 1000 is still okay. If you had a very simple character and you use just the sorting orders off plus 70 minus 70 for this character, even 100 and not 1000 will work. So that's how this stripped sorting order fixed works. And the important part here is this were also populating this dictionary that is called old transforms by name and will use it later in our other scripts to re skin this character. So thanks for your attention and in our next lecture will actually start talking about re skinning our characters and applying different outfits and different body parts. Do them. Thanks for watching and see you in the next lecture. 6. Scriptable Object Assets in Unity: Hello, everyone. And thanks a lot for watching the scores about making custom duty characters and in this lecture will start exploring the topic off, re skinning your characters. So, for example, you have this main character that we have assembled, and we want him to look differently. We want him to look like one off our two other characters. And to do that, the first thing that we have to do is treat the outfit or the look off our character as a certain set off information. So the info that we need to re skin this character and change the way that he looks is we have to know which sprites are going to use for his arms, the upper parts, the lower parts for his legs. So we need to know which sprites do we want to use for each and every part of his body. And sometimes we would also like to display some unique items, like maybe you have some bracelets, or maybe he'll have some necklaces or whatever that is that these characters have. So there might be some unique items that we want to display on these characters as well. So in this lecture will take a look at another group off scripts that is located in our folder character outfits. So let's open the folder one of the scripts, It's cold outfit Supplier, and we'll take a look at that in probably in our next lectures. For now, there's another very important script that we need to take a look at to understand how we re skin our characters in this project. So there is the second folder that is called S O Asset Scripts. Here we go to outfit Asset, and there is this script that is gold outfit asset. One outfit acid equals one outfit that you can apply to your character. Let's take a look at this script in mono develop. First, we have these two helper classes that are called unique outfit item, and the 2nd 1 is called Joint Info. I can't expand and collapsed these blocks of code. For now. We want to look at this main class that is called outfit acid, and the first thing that we can notice is this Glass doesn't derive from Mona behavior, so this not a component, and it doesn't describe the behaviour off our character. We cannot attach this glass as a component to a game object, and instead it derives from this other type that it's called a script herbal object. It is convenient to use script herbal objects when you want this glass to represent a certain collection off data. So you don't want this class to be inside of your game cycle. So no methods like awake updates, fixed update and so on and so forth. You just wanted to hold a certain amount of data for you to use in your game inside of the body of this class we have these new interesting thing is that our cold attributes and these are the things in square brackets that you can see here, and they will affect the way how your class will look in the inspector. So without fighting a custom editor class a customs inspector for your outfit asset. By introducing these attributes, you can change the way off how your class will look in the inspector and bring certain order into your class. So these things that are cold hatters, they will be displayed in bold In the inspector, you will see how they look in a couple of seconds This next thing that is called the text area will allow you to input a couple of lines off text into the inspector, so it is not an ordinary single line string. Instead, it it is a text area that will show from 2 to 3 lines off text, and it is cold public string description. Actually, this description field is not that important for us for re skinning the characters. But you can store some other data in your outfit asset as well. For example, if you want your characters to have different amounts off, health may be different strength off their attacks. You can also store all this information in your outfit assets. And when you change the outfit, you also change the properties on your character just as an idea of what you can do with this approach. Then we have this next attribute that says Space Stan. It'll just provide 10 pixels off empty space before our next header. Then we have this next header that will put the line that will say had in bold into our inspector. And just by analogy, all these next headers will work in a similar manner and all these public fields that we have here. They are off type Sprite, and when we say Sprite, we mean an image. So we'll be able to drag an image or one off our sprites that we have got out from all those images that we had from our assets folder onto an instance off our outfit acid in the Inspector. So we'll have the sprites for our head. Eyebrows, eyes, mouth. Essentially, these are all the parts that we need to change the look off our character and make him look differently. And not only that. So if we have just these public fields off type Sprite, it means that we can re skin our existing characters. But we cannot add any new body parts to our character. So if we want to add, for example, in necklace or a bracelet, we either have to introduce a new body part here and onto our character or we can do this next thing. We also have this public array off unique outfit item that is called unique items. So as we have discussed in our previous lecture, we have an interesting script that it's called the sorting order fixed, and it will contain the information about all the transforms on our character and this rate off type, unique outfit item. It will contain the info about some extra items that we can place on our character. And we can make these items a child off our arm or the leg and by making a child, were actually attaching these items to our arms or legs and will be able to control the placing spacing rotation of these unique items. So let's scroll all the way up and take a look at this glass unique outfit item. There are several feuds. The 1st 1 is public string name, so this is a name for your new item. If it is a bracelet, it makes sense to call this item bracelet. And if it's something else, he call it something else. Next field. Public Sprite picture. So you'll just drag one sprite from your assets folder onto this picture field in the Inspector. If you decide to have unique items on your character, the next field is interesting. It is a string, and it says child off. So since we have all our transforms stored in a dictionary and the dictionary holds the strings that are keys to our dictionary and the strings are in names off the game objects off our transforms and this child off. It'll search for a game object with this name, and it will attach our new unique item to this transform or to this game object. We are also able to control local position and local rotation so you'll be able to find you in the placing and rotation off each of your unique outfit items. You're also able to control the local scale and finally, in the light off what we have seen in our previous lecture with these layered characters, it is very important to said the correct sorting order. So for these unique outfit items, you'll said the sorting order off these items manually. So maybe you'll have to go through the process off trial and error and then come up with the correct value for this sorting order. And finally, we have another interesting system inside of this outfit. Asked class. It is not something that will use right away but will use it later. For example, you want to apply the outfits two different types off characters and you want to any mates all of them with one animator by different types. I mean, let's say one of your characters has wider shoulders or one of your characters has shorter legs, and you still want to be able to describe this character by the same character model, and you want to use the same animate or the same everything and the same outfit assets. So to achieve that, there's also this class that says joint info, and it is much simpler than our previous class. It has to feels the 1st 1 is public vector to local position that will allow us to control the blazing of thes joints and will make a more complicated character with joints later in this course and the second field public float local rotation will allow you to control the rotation of the joint, and this info is also reflected here in the body off our outfit s class. There's a hatter joint information, and we have these public fields of type joint info that are gold torso, joint neck joint, closer shoulder, joint elbow joint. So they're all these various joints that who placed on our character, and it will allow us to apply outfits. Two characters that are shaped a bit differently. One more important thing when you are making a helper class inside of unity, such as our unique outfit item or our joint info, you want to make sure that you include this attributes on top that says system. See, realize herbal. And if you don't do that, he will not be able to see and edit instances of this glass in the inspector. So make sure that if you want to edit some custom class in the inspector, you want to include systems serialize, herbal on top and one more important point to achieve what we want. It is not sufficient to just create a class of type outfit asset and have it somewhere in your project. So once you do that, you are still not able to create your custom assets in unity. In order to do that, you need to include two more scripts that are actually editor scripts there much simpler than this one. So let's take a look at them. This script is cold script, herbal object utility to For some reason, it is a static class, and it has a method that is called create asset off type t. So it is a generic method and you can create assets off any type where T is descriptively object. So the type has to be a script herbal object. It has just a couple of lines of code. And I don't think that you have to memorize how this class works. Were just using this class to achieve our goal off, creating our script herbal object asset in unity. So that's the first class and will use it in this next class. So for each script herbal object glass that you want to turn into an asset in unity, you will also have to right this small class that will be called something something unity , integration. Actually, the class can be called however you like. But here we make this attribute. We specify the menu item, So when we go to assets create now, we'll be able to create our outfit assets. And without this class, we would not be able to do this, and the only method that we have in this class is very simple. It is called creative rescript herbal object, and it has just one line. We access our previous class scriptural object utility number two, and we call a method great assets of type outfit acid, and that's it. So that does the trick for us. And finally, now that we have discussed everything, I'd like to go to unity and show you how this works. So I'll return all the way back to our Assets folder. I will, Right click. And just for convenience, I'll create a new folder and alcohol this folder outfits And inside of this folder I can right click again, go into this, create Manu and here in this long menu will now have a new option that is called an outfit asset. And now we can create one. So let's create in you outfit asset. Let's go. This guy number one, for example, I'll press enter. So once you have these scripts in your project, you can create your own custom assets in unity that will hold the data that is important for you in your game. And since I have discovered this way off managing data in unity, I have included this in one way or the other into almost every single one of my projects. So it is very convenient, and it can save you a lot of time. And if we go over here into the inspector with our outfit assets selected, you can see that it is structured exactly the same as we discussed in this video. So we have these hatters that are highlighted in bold. We have one that says General Info, and then it contains this public field that says description. We have the header had and old the sprites that are related to our head. We have the sprites for the body, the legs, the arms. We have our unique items and hear this Ray is now empty. So let's add one element to this ray. And since we have made our unique item class serialize herbal, we're now able to add it all the fields here so we can type a name at a picture, make it a child of something, change its local position, rotation and so on and so forth. And we also have the info about all these joints. So we're able to add it the local position and local rotation off our joints. For now, that's everything that we need. And in our next lecture will discuss how to added our outfit assets and how to apply the look from your outfit asset onto your character. Thank you very much for watching. And I will see you in the next video. 7. Applying Outfit from Asset: Hello, everyone, and welcome back to this course. So in the previous lecture, we have gone through a process off, creating your own script herbal object assets. In your project, you can store things like conversations, the stats of your characters, and so on and so forth. It is very convenient. And in this lecture we want to add it one off our outfit assets, and we want to apply it to our character to make him look differently. First, if you want to add it your asset or edit anything in the inspector that involves some other objects or other things in your Assets folder, it is convenient to lock the inspector this way. When you browse other folders inside of our Essence folder or select different objects, they will not show up in the Inspector and the inspector will be locked to this individual guy, one outfit asset. So now we can go to our assets sprites characters and let's select the first guy because we have called this acid guy one and try to apply all the different body parts from this character onto this outfit acid. So first, let's go with hat. I'll drag this hat Sprite onto the Hadfield in our outfit Asset in a similar manner. I'll drag the eyebrows, the eyes, the mouth, and I will go on doing this until all these fields are populated with sprites. And for now, we will not touch our unique items or our joint information. So I can just you raised this unique item. I can type in zero here. So who have zero unique items for this character and will not change any information in our joint info. So now I'm done with editing this outfit asset and all the information about how we want this character to look will be forever saved in this guy, one outfit, asset and the next step if we want to apply the look from this asset onto our character, we have another script in our project that is located in assets, scripts, character outfits. And it is gold outfit, a plier. I can unlock the inspector for now, and this script is Amona behavior, so we can actually attach it to our character. And let's do that. I'll select our character here. I can collapse all these gliders and the controller. I can actually apply the changes to the controller because this speed parameter was highlighted. So let's do that. And I can add another component. Aiken, search for outfit, apply or here. Or you can just grab outfit a plier from our SS folder and drag it onto our character here in the Inspector. Once the outfit supplier is added, you can see that it has all these different fields, and we'll have to assign something to all of them or nearly all of them. So, just like with our assets, it is easier to edit anything if we lock the inspector. So I'll go and find this little look I can hear on top of the inspector and I lock the inspector on this character object and the logic behind all these references here, their references to Sprite renders. So they hold the info about all the body parts with Sprite renders that we can use to apply the images from our outfit assets. So let's just go on and feel in these couple of first sprites, so I'll expand our character. I'll find the torso, the neck that had because we're starting from the head and I'll drag This had object and you can notice when I select the head. Previously, the had game object would occupy this inspector here and now. Since we have locked the inspector, this is not happening. So I can just drag the head onto this Hadfield in our outfit supplier, and it will establish a connection with a sprite render on our head the same thing with our eyebrows, the eyes, the mouth and in a similar manner. I'll go on and fill in all these other Sprite render fields. So now I'm done with this task. It took me about a minute to drag all those body parts onto our outfit supplier. Do not touch our joint transforms for now because this character doesn't have any joints. And as you can see, there's also this Jack mark that says Use joints on top off our outfit supplier. And it is currently unchecked. So since it's unchecked, our script will not try to do anything with our character joints, and we'll discuss what we can do with those later. And now we can apply these changes to our character. So once a hit apply, all the information is saved in our prefab. So these same connections, their true for all the characters, the connections we've had, the body, the torso and so on and so forth. Later, if we decide to do the same for our MP sees, it will be more convenient to create in you NBC prefab out of this character because you will not have to go through the process off reestablishing all these connections again. And finally, the last and the most important field here is this field that says initial asset and it is off our type outfit asset so we can grab our outfit asset from here from our Essence folder and drag it right onto our outfit, a plier script. And let's do that. I'll go to assets outfits. We have just one outfitted that is guy one outfit, and I'll drag it onto our outfit. A plier script. Now there are several things that you can do to enhance or change your outfit. A plier script. Here you can see that we have all these separate things for our had eyebrows, eyes, mouth century. Actually, you can use a similar approach that we use with our unique items so you can just have an array and access all these different items by their string names. And then you will not have all these individually named Variables in your outfit a plier script and actually in your outfit, assets whipped. But I like it this way a bit more. So you get these more defined features that represent your character has had his store, so the eyebrows so you can see all the body parts. You know that you haven't missed anything. You are insured that you have not made any typos here, so I like it better this way. When you have this huge list off pre defined variables, it seems to bring more order into your scripts and into your workflow. And now, finally, let's launch the game and check out how it works. If we have done everything right than our character, he should look exactly like our guy won. So, like a different character from our art back now, if I launch the game and this is exactly what has happened, so now we have one of the characters that is our NBC. That looks exactly like he looked before and our other character, he now has a different outfit, so we have re skin them, and he now looks differently, but he retained all the functions off our character, so this character is still described by the same model. He has the same any major, and he uses the same animations to move, to jump onto platforms to jump off off platforms. So he has absolutely the same functions, except he looks a bit differently, and that is exactly what we wanted to achieve in the next lecture. I think we'll take a closer look at this outfit, a Blier script, and we'll discuss exactly how it works. Actually, it is not difficult at all, and later on we'll discuss more complex and interesting things, like adding unique items to our characters and introducing joints to make characters that are different, the shape characters that have different complexion. We want them to be described by the same character model, share the same animator and have the same behavior in our game. Thanks a lot for watching, and I'll see you in the next lecture 8. 108 Outfit Applier Script Basics: Hello, everyone. And thanks a lot for watching the scores about some advanced stuff for making duty characters. In the previous lecture, we have finally made our own script herbal Object Asset that describes one outfit off our character, and we have also first used the script that is called Outfit a Plier that will apply the look from our outfit asset onto our character. And we have already checked that it works. So I've made several changes to our project since our last lecture, mostly the mechanical stuff that you can do easily yourself. So I've created these two other assets for our remaining characters and another change that I've made. I've created new pre fabs for our MP sees because they were not using our outfit a pliers. I have made this NBC script sorting object out off my character object not to re establish all the connections again. I deleted all the previous pre fabs, and I have made two new prefects for our NPC script sorting and NPC sorting layer. Now, both of these pre fabs they have our outfit, a pliers script attached to them. So these are all the changes that I've made now, if we launched the game, you can see that both of these characters, they look differently compared to how they looked in our scene. We can control one of them, and the 2nd 1 is an NPC character, and they all use our script outfit a plier, to apply the look that we have selected for them with our outfit assets. Our go for this lecture is to take a look at the outfit a plier script and discuss how it works. For now, we will mostly focus on the simple part, the part that applies different sprites, two different body parts off our characters. So I'll exit play mode. I have this script already open in mono develop. As I already said, this script is amount of behavior. Structurally, it starts off very similar to our outfit assets script. So we have all these spaces and Hatters and instead of sprites there now Sprite renders. So they are. The sprite renders on different body parts on our character, and in order for this script to work, we have to find all these sprite renders, and we have to establish connections with them manually in unity. We also have this first public feel that is very important. It is of type outfit asset. So it turns out that we can make a public field off our script herbal object type, and we can drag our script herbal Object assets from our assets folder onto this script. This allows us to do that and this we, our character, will know how we want him to look. We also have this public bullion that is called used joints, and we'll get the joints eventually. For now, we're not using them. So we have this long list off all these public sprite renders. And as I already said, you can sort of automate this process and you can make this script search for the sprite renders and the body parts by the name off transforms or by the name off game objects that thes Sprite renders are attached to. This way, you will not have to specify all these separate public Sprite renders. You just create your own serialize herbal class that describes all the sprite renders on your character, and you just feel it in like an array. So you create an array of the class, and I like this approach a bit more because I know exactly which body parts do I have on my character, and it all centers that I don't make any typos. So then we have the info about our joints transforms that are just empty game objects that mark the places where we want to place our joints, and we'll get to them later will create a whole new character that has all the joints to demonstrate that you can any major character once and your character can actually look very differently. He can have whiter shoulders, short legs, etcetera, so you can use one animated model to describe many different characters. We also have this private field, off type outfit asset that is cold current asset. And next we have a public property that exposes this field, and the reason for having it here is you might actually want to spread, swept or re skin your characters even in the process of the game. So you might make your character turn into someone else, or you might make him look differently in the middle of the game, For example, change his hat, change something else so you might have different outfits, and you can apply them to your character dynamically during the game, so his first field that it's cold initial asset. It marks the asset that we are applying to this character on the wake. And then during the game, you can apply a different asset to your character, which is critical. Next, we have a reference to our sorting order fixed, stripped and the purpose that it serves in our outfit. A plier script is it holds the data about old child objects off this game object and will need this data to place our unique items. We also have a private dictionary and you have already seen dictionaries in our sorting order fixed script. And here it is a dictionary with string keys and game object values that will use to track our unique items that we have created for this character were initializing this dictionary with an empty dictionary of this type and that's it. The next method is awake. Awake is a method that is used to establish all the references that we have not established in the inspector because we didn't want to have any extra public fields. So here we find our data about Children, which is our sorting order, fix by saying Get component and then instantly in awake if we have something signed to our initial assets, So if it is not know, then we gold This method apply look from asset. So by the end of this awake math at your character will already look like you wanted him to look by making this initial asset and then this method apply look from asset. It doesn't look too difficult, so it just applies the info from our outfit assets to this character in certain stages. So first we have to save our current asset. We say current asset, which is a private field, equals two asset, and it's mostly useful if you are sprites, Wapping or re skinning your character during the game. So you're saving the acid that you are currently using. Then we call this method. In my case, it is called apply. Look to front. Previously, I had a more complex character that had a front view and the back view. We use them much simpler character about the name of the method remained so apply. Look to front is a method that will find all the body parts that represent the front off our character, and it will make sure that all the sprites display the sprites from our outfit Asset. After this stage, we golden method hide unique items. It is not very intuitive if you are just's initially applying something to your character because he doesn't have any unique items for now. But if you are sprites, Wapping and re skinning your character during the game, you might assign one set off unique items to him, and then you want to sign a different set of unique items to him. So it makes sense to first hide all the previous unique items and then display those unique items. With this next stage, we display the unique items that we have created using our outfit asset and the final stage . If our use joints check mark in, the Inspector is checked, were also calling the Method place joints from asset that will change positions and rotations off our characters shoulders, maybe knees, his elbows and so on and so forth. So old the joints that he might have. We can reposition them, and the sad back is that our character will get a bit more complicated in the hierarchy, he will have much more different game objects. But the benefit of this approach is that you can use the same any mate or for characters that look drastically differently. One can be shorter than the other. Or he might have some normally sized body parts or something might be displaced. And they're still animated by the same animator, which is pretty cool. And now let's take a look at our main method that is called apply. Look to front, so I'll expand it. All these methods are currently collapsed in mono developed, and you can press on this little plus sign to expand any of the methods. So the method is actually long, and it is so long because we have to address each individual body part that we have differently. So the structure is very much the same. So we're doing the same thing for each and every one off our body parts. First, we're checking if we have a sprite in our asset that represents our head in this case. So if acid don't had which is a sprite is not equal to know, then we'll say had and now had means different things had in this script is a sprite render , so we'll find the sprite render that represents our head and will set the sprite to be equal to asset adult head and another thing. Sometimes you might want to hide the head. Or actually, usually you don't want to hide the body parts of your character like the head or the arm. But you sometimes want to hide elements off clothing. So if it was an element of clothing like a sleeve or something like that, you might want to make it hidden while you are editing your character in the scene. And then when you apply the asset, the sprite render will get re enabled. So here you are, making sure that your had Sprite render is enabled and visible for your players and else. This next else statement is also mostly useful for closing items. If you haven't assigned any sprite for this body part, or for this clothing item, you will just say Sprite render, which has had in our case enabled, equals two false. So if your character has no shirt, for example, you will disable the sprite render that represents the shirt on your character in the scene and your players will not be able to see which is exactly what you want in this case. So now that we've gone through this if statement, we have absolutely similar. If statements for all the other body parts, the next game, the eyebrows etcetera, etcetera. So we have these very similar if statements until the end of this method and the end off our script. So now that you know how we apply our outfit assets to our characters in our next electoral talk about displaying unique items on our character will take a look at this next method or these couple of methods their gold hiding items and display unique items. And we'll try to add some unique elements, like bracelets, belts, necklaces to our characters. Thanks a lot for watching, and I'll see in the next lecture. 9. Displaying Unique Items: Hello, everyone. And thanks a lot for watching the scores. In this lecture, Argo is to look into some more interesting features off customizing your characters and will try to add unique item to one off our characters. So I have already opened our first asset, just called Guy one and looked the inspector on it. I've added one unique item, and now we'll feel in all these fields that will help us bring this unique item into our game. I think first, let's try and add this belt to our character. The belt should appear on top off our skirt game object. So let's get into it and let's fill in the name for our new unique item. It will be called Belt as the Sprite will use the belt Sprite from this first character that we have. So I'll just drag this sprite onto here. It will be a child off. Now. This part is a bit trickier, so we can expend our character and find his skirt game object. It is called skirt, so we can just copy the name of this game, object by pressing control, see here and basting it into here into our assets into the description off our unique item . For now, let's strive not to change the local position so it can be 00 and we later adjusted. There are several ways off adjusting this local position off your unique element. We can also try to add some locals add rotation. I don't think who need this, so let's leave it at zero as well. For local scale, we have to select 11 because if your local scale off this game object who remain at zero, you will not be able to see it. So who said this to 11 in X and Y direction and for the sorting order? I think we can already said the correct sorting order for this element. So I will unlock the inspector to see the sorting order that it's set for our skirt. Our skirt has an ordering layer off 30. That's why, for this element, we have to set something a bit higher so that we can see this belt on top of our skirt. I think let's try 32 or something like that, so I will return back to our outfits, select our guy one asset, and I'll type in 32 here. So now that this info is saved into our asset, the only thing that can go wrong is this local position. So let's launch the game and see how it works. We can go to the scene view and zoom in on our character. So the local position is a bit off this belt, it appears, been higher than we wanted to be. And there are several ways of fixing this. First we can play with our local position here and all the changes that we introduced here . They'll only become visible when we relaunch the game. And to get a better idea of the local position that we have to set here, let's find our belt. So I'll expand the scared game object. And as a child of it, we have this belt game object I can select this to, and I can bring it a bit lower. So a more appropriate local position for this game object is minus 0.14 and maybe we can also play with its scale. So it is a bit larger in X x x, actually, then I expected so if the belt will look like this, so 0.82 in X scale and minus over Teen in Why Local position and I can just memorize thes values or I can ride them down somewhere and then I will bring them into our description for this unique item. So let's exit play mode. I'll go to our guy one asset and our local position should be minus zero point for thine here, and our local scale should be 0.82 in X excess. So now if we launched the game again, then this belt, it will be placed exactly how we wanted to be. And we can try that with another item. So just for the sake of demonstration, I'll try to do the same thing on my own with a necklace. Our characters, they also have necklaces, bracelets and so on and so forth. But the logic off placing these items is always similar. You creating you unique item and you place it on top off some other item that your character already has, like, leg or a skirt or torso or something else. So I will try to place another unique item and then I will get back to you. So now I am finished with a blazing another element onto this character, which is enact lease and the necklace needed very little adjustment. I had to adjust the Why local position, because the pivot point off our torso is here in the lower part where it's sort of attaches to the legs. So the necklace had to be raised all the way up towards our neck area, and now it's place where we wanted to be, and we can now move our character and he will get dressed up with all these different unique items that we add to him. So it is pretty convened. He can jump, he can perform all the same actions. Madonna can decorate him and come up with some you and interesting combinations, and we can do the same thing with our other characters. I will not do that not to take up a lot of time, but in do it yourself. So another thing that I wanted to talk about in this lecture is how it is old done in scripting placing of these unique items, creating them and adding them to our character. And we also have a method that it's cold hide, unique items, so let's take a look at them. It all happens here in our class outfit Blier. If we scroll a bit lower, there will be Oh, these methods apply. Look from asset that calls our methods hiding items and display unique items. Please joined for assets We have no disgusted yet and we'll discuss this in the next couple of lectures. First, let's take a look at this simpler method that is called hide unique items. Essentially this method, just it rates over all the unique items that we have already created and all the unique items that we create. They go to this dictionary unique items created, and it is quite interesting. That dictionary is a collection that holds these things that are called key value pair. So this key value pair that is specific to this dictionary will hold string keys and game object values. So we say, for each key value pair that is called pair in our unique items created and we'll say pair dot value, which is our game objects who get a component of type Sprite render and we'll disable this component. So even though this game object will still be there, the Sprite render will not be visible, so your players will not be able to see this unique item. And then we have this next bit more complicated method that it's called display unique items. First, we check if our outfit asset has unique items, so if they're rate off, unique items is not equal to know. And if its length is greater than zero. So if we don't have any unique items, there is no point in executing any of the code that we have next. So we have to perform this check. Then we iterated over this race. So we say for each unique outfit item you Oh, I in asset unique items. And for this unique item, we usually have to create a new game object. So here we say, game object, new item equals to you game object and for now we don't do anything with it. Then there is this interesting check. If you are changing the look or changing their appearance off your character mid game, then you might already have this item. For example, in your previous look, you have this item and now you want to re enable it once again. So for this purpose. We are checking if our dictionary off unique items created. It already contains the key. You Oh, I name. So this item it was once created. And now you want to just re enable it. Then you will say unique items created. So you access your dictionary. You can access an element in your dictionary with this syntax that is similar to accessing to an item in an array. But instead off putting and index, which is just an integer number in these square brackets. Here we have to put the key off our addiction here, which is a string. So say unique items created you. Oh, I name will try to get component of type Sprite render and will just enable the Sprite render. So if this unique item wasn't visible before, we want to make it visible to our players and will say sprite render enabled equals true. And then it turns out that in this situation we no longer need this game object that we have created that it's cold new item. So we have to say destroy new item and else the stents for the case when this unique item was not previously created and this code will be called in most of the cases and it will do most of the job here. We have to say in you item transform, which is a transform on our new empty game object. And we say set, parent. And here we are, accessing our data about Children that stores all our transforms by name Old transforms My name is also a dictionary and we are also accessing its elements by names. So we say you oi which is our unique item and the thing that is called child off. So the name off the transform that we want to make this element child off. And after this line, this new game object will become a child off a transform with this name child off in the higher Currently, this game object doesn't have any means of showing our sprites. So in this next line, we say sprite render s r equals new item. So our game object and we are adding a component of type sprite render to this game object and then we have to set old other info that we know about this sprite render from our outfit asset. So we'll say as are sorting layer name and we'll set it to player. Actually, this is quite questionable. So if you want to have your unique items and have your different characters on different sorting layers, you might want to change this and add it as another field into your unique outfit item. For now, I think setting it to player is fine for us. Then we'll also set the sorting order off our sprite render and we'll get this sorting order from our unique outfit item plus and this is an interesting part. So in awake your character, he has already been displaced, sorting order wise by your script sorting order fix And this info is contained in this render offset property. So we also add our data about all Children that render offset. And we'll set the sprite that we want to show on this sprite render to be equal to you. Oh, I dot pictures. So the picture that we want this unique item to show to our players because this is in use bright, we are adding, it's to our data about Children, all sprites. Maybe you want to change color on all the sprites or do something else So it's nice to have the info about all the sprites, including your unique items that you add a bit later. And then we have to resolve all the remaining stuff, which is the name of this new game object. We also take it from our unique outfit item, and we can displace it so we can give it new local position. From that info. In our unique outfit item, we can change its local rotation. So if we wanted, we could also rotate this item in that X is and we can also change its local scale and old info is contained in our unique outfit item. And finally, once this is done, we can add this game, object into our dictionary, unique items created, and it sums up this method and older code that we need to apply unique items to our characters. It might seem a bit complicated, but actually everything in this method is not that difficult. You just use the same approach off applying the information from your outfit asset onto your character, and it works like a charm every time. So it is reliable and you can place a lot of different unique items onto your character. But because we use dictionaries, you have to make sure that the names of these unique items are also unique. So if you want to have two bracelets, you can't call them both bracelet. Call them bracelet one and bracelet, too, in our next lecture will cover the final topic off the scores, which is using the same outfit assets system for re skinning characters that are shaped differently. So the characters that have wider shoulders or shorter legs will come up with a universal system that can be applied to all these differently shaped characters. I would like to thank you very much for watching and I will see you in the next lecture. 10. Character With Joints Part 1: in this lecture will discuss the final bids off material that is planned for the scores, which is making a character with joints and applying outfit assets to characters that are shaped differently. So let's get into it, and the first step that we have to take to achieve this is make and you prefab do not accidentally apply the changes to our old character Prefab. I'll make a new character, and it will be called a character with joints. I'll drag it into our SS folder and making you brief up out of it. As a general principle, you can add joints to anything that bends or anything that attaches to some other body parts. So in our case, who have all these joints and let's just for a demonstration, make an elbow joint, so I'll go here. I'll select our low closer hand and elbow joint is something that we want to have in the points off attachment off our low closer hand to our top closer hand, and the process that I came up with to make these joints goes as follows. So I select element that is attached to this joint. I right click and I create an empty game object, and I call this game object. A closer elbow parent, for example, I've made a child off our low closer hand just to copy the position off our low closer hand actually should be the other way around. So in the scene, I'll focus on this game. Object with this, too. So it is in the same place where our low closer hand attaches to our top closer hand. Now we can grab this closer elbow parent and let's drag it above our lo closer hand and I'll make another game object. So I'll right click on our closer elbow parent, and I'll name this new game object just to closer elbow joint. So this game object is actually our joint. And this closer elbow parent is just a parent game object, and we want to have this structure in our hierarchy because we'll control the placement off all these joints by changing local position relative to their apparent. So we have the parent, we have the joint and now we have to grab our low closer hand and drag it onto our closer elbow joint. It will say that this action will break the prefab instance, and we're totally fine with that will apply all the changes to our prefab once we place all the joints in a similar manner. So now if you have the character that is shaped differently, for example, he has hands that are a bit more fat or a bit shorter, and your low closer hand has to be placed in a different position. Then you can control the positioning, not off the low closer hand game object but off the closer elbow joint game object, and you can control its position and rotation relative to this closer elbow parent. So you dragged the joint and these two objects the parent and the low, closer hand. They maintain the same transformed position and transform rotation. So I'll just bring back. It is joined back to where it was so that our character works normally. And now I will go through this process many more times and I'll create and you joined for every elbow, every knee, every hip for our torso and for our neck. And then I'll get back to you with the results and we'll discuss how we can benefit from laying out our character like this So I am back and I have gone through this same process with each and every off our joints, and now our hierarchy for this character looks significantly longer. So let's just inspect how it'll looks so even for the tour. So I have created this game object, torso, join parent than in the same position, same everything. There is a torso joint and then as a child off this ghost, our tour. So the same thing for the neck neck joint parent than neck joint and then the neck itself. So between each and every one off these game objects, there are two extra game objects. One of them is called the Joint Parent, and the 2nd 1 is called The Joint. And the next step for us is assigning all these joints into our outfit supplier. So if we select our character with joints than here in the outfit a plier, there will be old thes different joint transforms. So I'll look the inspector and I'll grab our torso joint and bring it onto this first joint , and we care only about the game objects, their actual joints so we don't care about the parents or the tour so we just grab those game objects that are cold joint. So the next one is the neck joint and then we have our closer knee joint and our remote knee joint, and that's it. So now our outfit supplier knows about all these joint game objects or about all these joint transforms, and we can now apply the changes to our prefab and next. It's quite interesting. If we now launch the game, let's try that and we can try to walk with our character. Something is wrong. He's no longer walking the way he was walking previously. So something has changed and we have to figure out what's wrong with our character now. And if we select our character with joints, the game object that has the any mates or and we go to animations, let's select our walk, animation and all these different game objects. They're highlighted with yellow, which means that we have lost connection with these game objects. And it all happened because we have introduced a couple of new game objects into our hierarchy and unity now cannot find the previous game objects that we were using to any mates. Our character and previously It was a very hard thing to figure out how to bring back all these references back into your animation, because currently the animation clearly doesn't work, and I've found a very interesting too. So I'll exit the animation. For now, let's go to our project. And there is this little folder that it's cold animation hierarchy. It contains just one editor, script animation hierarchy CS, and it allows us to reestablish all those lost animations that might happen to your animated character. When you change something in hierarchy, it is a very, very useful utility, and sometimes people even feel desperate, and they have to redo and re animate their character from scratch. But there is no need to do this so we can go to Window and opened this animation hierarchy . Editor. There is this little window that beers, and we can drag it wherever we want. I'd like to drag it here to the lower part off our inspector, and we have to select animation clips. Our animations are in assets, animations, our character without joints, which actually brings us to the next interesting point. If I try and replace all thes animations for the animations that will be appropriate for this character. Our characters without joints, they will no longer work. And what I want to achieve is I want to make all our characters working similarly in the same project. So in order to do this, there's an interesting to in unity that is called an override animation controller So I can create another folder and I'll call this folder character with joints this time and inside of this folder, I will right click, go to this create menu and I'll create and any mate or override controller, and I'll call this override controller character with joints controller. Now, when I have this controller selected, I have to unlock the inspector and we have to specify a controller that we are going to override. So currently it says none. If I press on this little circle sign here will have access to all the animator controllers that are in our project already, and the only one that we have is this character controller, so I can select that, and now we have to come up with completely new animations For this character. There is no need to create new animations inside off unity. We can just create a copy off our previous animations, so I'll have to go to the Explorer. I'll just right click Select Show in Explorer here, go to our folder character without joints, and we have all the animations already present here and their idol any hour jump animations . So I'll select that. And I am not concerned with all these metadata and, of course, our walk animation. I'll just press control, see to copy them and I'll be turned back and I'll paste them into our folder character with joints. So now we have all the animations that we've done for our previous character present for this character as well. But all the connections there still not established properly. So if I returned back to unity, these animations beer here we can rename our animations by adding a single symbol, for example, a J to all the animations so that we can distinguish between our previous animations and these ones that we were going to edit right now. And I'll just rename each and every one of these animations with the letter J prefix. Now all the animations are renamed, and as we select each and every one of these animations. Some info shows here in our animation hierarchy tab and let's go through this process for our walk animation. The first thing that we have to do to edit this animation is to set our referenced route animator. And in order to do this, we have to first select our character with joints. And since we have created an animator override controller, we have to assign it to this. Any major so instead of character, will now use this new character with joints any major. Now we can go back to our jaywalk animation clip, and we can select reference any maze air here from the animators that we have in our scene . So we want to select an animator that's on our character with joints. So let's do that. And the only reference that is currently established correctly is a reference to our front view game object. And that is why we were able to see our character jumping up and down a little when he's walking. So now we have to re establish connections with all the other game objects that we have here and our animation hierarchy script. It tells us that previously we had a game object that was called top remote leg. So we have to find this game object on our character and drag it onto this Redfield that currently says none. Here's our top remote leg. Let's drag it onto here, and it will re establish this connection again. So next we have, as a child off our top remote lag our Lou remote leg. So let's find that as well and drag it onto here our top closer leg. So we ignore the joints. We just want to get references to the game objects with the same names. Then we have to be attentive. The next game object that we have here is our top closer hand. So let's find that here's our top closer hand and let's bring it over here. Our low closer hand here is this Next game object. Then we have our top remote hand lo remote hand. We have the neck, and finally, the last game object is our low closer leg, and the final step that we have to take before we can check our walk. Animation is we have to select our override controller, and the purpose of this override controller is to replace all the animations that were previously in the controller so old the States like Idol walk, jump from 1 to 7. They have to all be replaced with new animations. Maybe not all of them, but some of them if it is suitable for your character. So now we have to lock the inspector on this object and just drag all the animations like J Idol, jaywalk and older jump animations into our controller. So starting from one and seven. So we haven't done this for jump animations yet. I mean, reestablishing the connections in animation, charity but walking, shoot already work in the project. So now if I launch the game, our character, he's I'm sorry for this abrupt transition. It seems like we have done everything right. But as we launch the game and let us launch the game together to test this, our character appears. And when he starts walking, one of his legs is moving really weirdly. So I I was trying to figure out what's happening and what's wrong with this character. It turns out that if I launched the animation and I tried to check how the slag actually works here, it is displaced for some reason, and it seems like I didn't make any mistakes with the joints or with anything else. So if I select my closer knee joint, it's here where it's supposed to be. And if I select my glow Sunni baron, it is also here. So we have to just grab this leg Sprite and place it where we want it to be on each of these animation frames. And the reason for that is as they said, it is best to not use position here, so I think that we can just delete this position. Line old together, so I will select position and just hit. Do it here. Now Let us adjust the position here for the first frame, and we don't have to move this closer me joint. Instead, we have to move our low, closer leg. And now, if we launched the animation, it looks like a more believable and more appropriate animation for our character. So I'll stop the animation from playing and from recording, and now if we launched the game, our character will be able to walk just like our previous character. But now he uses all these joints, so I'll spend some more time to establish all those connections for our jump animations. As you remember, I can return to our project and select our jump. One jumped to jump three, and I'll bring all the body parts and revive all these different jump animations. And it turns out that you can even multi add it all these animations. So I have multiple animation clip selected right now from jump to all the way to Jump seven . Let's edit them in a similar manner. L grab our top closer leg from here. Al. Grab our low remote leg here so it seems like the list has also changed. So it has loaded all the reference bath or all the body parts from all our animations, which is good. So for the top closer hand, let's do that. Now let's check out each of these individual animations. So it turns out that you can re establish connections with these body parts when you are multi editing your animations, which is another plus off this amazing animation higher CA script. Now let's launch the game and check out that everything works. So our character, he's already jumping, and sometimes the leg also doesn't behave like it should, so I'll return back and I'll correct that in our jump animations. Now we've our character with joint selected. I don't know why it happened. I will select our jump animations like jump one. I also like this leg that doesn't want to behave as a true and I'll just place it properly on each and every one off our animations, just changing its position. And that must be it. So we have done this for all the jump animations. I will stop this animation from recording. Let's try this again. So now if we jump, our leg behaves appropriately and it shows all the animations correctly. 11. Character With Joints Part 2: and finally, the purpose off all this was creating another character that will have a bit wider shoulders. So with our previous model, we can have done that. And let's try how it looks with our previous model. So now, essentially, if we apply the asset with wider shoulder torso, do this character, he will behave exactly like our previous characters. And let's try that will go to our outfits folder l create a copy off our guy. One asset. It's the one with all these belts and necklaces, since it is a bit more interesting, so I can just breast control D, and it'll create a copy off my asset. It turns out that automatically, Who called a guy four. So we have this guy for outfit Asset. It is absolutely similar to our guy won, except I have this custom sprite. I can go to our assets sprites, and here we have this new spread that is called a large store. So So I'll try and apply the torso skin instead of our old Dorsa will use. This larger version now will select my character with joints and instead of our guy, one outfit asset, I can press on a little circle here, and I'll select our guy for asset for this character. So now if I launch the game, here is the character and he looks almost all right except his shoulders are now a bit wider. That's why in the scene, if we zoom in on the character, the placement off his shoulders, it looks a bit off. So now we can figure out how we should place his shoulder joints to avoid this situation so I can select his remote shoulder joint and I can move it over here. Actually, we can write down these values, so something like 0.0 45 will work for both X and Y axis and for our closer shoulder joint . I will write down all these values and then I'll just type them into our joint info in our guy for s it. So now with this info written down, I can exit the game. Another thing that we have to make sure about. We have this check market. It's cold. Use joints for a character with joints. We want to keep this check mark checked, so I'll check the check mark and I'll hit, apply and Now we can go to our guy for outfit Asset that is in outfits Guy four and here for his shoulder joints. We have his closer shoulder joint. I would like to change the local position of this joint to the values that I have written down. So minus zero 0.39 and in why access 0.1. And for our remote shoulder joint, I'll use 0.0 45 I'll just copy this value for why excess as well. So now that we have this joint information, if we launched the game, then our character will have wider shoulders and his shoulder joints will be placed correctly. That will ensure for correct positioning off his hands. And if you have all those joints, so imagine, you can control the positioning off his knee, joins his elbow, joins his neck and hissed, or so and so on and so forth. It also means that you can create characters off any other shape with the same model. As long as you are satisfied with the animations that move your legs and your arms at a certain angle and it is appropriate for your other characters, you can use this same trick to re skin and applied Luke to your other characters. And at the same time, if we use this same model and we apply a different guy, a different guy asset to our outfit, Blier. So let's try our BDS guy. One asset that doesn't have wide shoulders. Will it work? Yes, it will work the same way as it worked before. So now this character, it can cover both our wider shoulder guys and our ordinary guys, the ones that we had in our art assets. And this pretty much sums up the material that I wanted to tell you. In this course. If you have any questions, please reach out to me and write me a message or a question in the Q and A section. Thank you very much for watching the scores. Good luck with your own interesting duty characters and duty games and good boy