To make the character wear clothing I did research whether there would be an easy way which would be good for performance. This was because in a previous project I learned to do it with disabled gameobjects and turning them on when needed. I thought there could maybe be a better way.
I found an asset which promised to be that better way. It was this asset. After testing I discovered that the asset only works when the characters and clothing have bones and ours did not (yet) have that and at this point I did not think they would in the future. Because I could not fix this quickly I decided to start doing research again and I found that almost everyone (that did not use a pre-made asset) did it the way I described in the first paragraph. So I started making it that way.
First I put all clothes on Bob (our avatar) and positioned them correctly. You can see this in this screenshot:
In these prefabs of the clothing I made them non-grabable and I removed all physics, because otherwise they would fall off. This is what the normal prefabs look like:
When making the normal prefabs I discovered that the grabbing did not work correctly and you can read how I solved that here.
Next I made a script I put on Bob which detects clothing thrown at him. In the inspector you can link all the gameobjects from the clothing that you want to use and the script will use these to detect what clothing has been thrown and determine which clothing he has to wear. This is what it looks like in the inspector:
It does this with the ClothingType class which looks like this:
I made this class to make it easier to add new clothing types and add new clothing to a type. One special thing about this class is the boolean fullOutfit. When you check this the code for dressing knows that the piece is a full outfit and removes both tops and bottoms from the character before applying the outfit. This also means that when you throw a top/bottom it removes a full outfit if present. This makes it so that you can combine all tops with all bottoms but you cannot overlay/underlay it with an outfit. You can read the script for dressing the character below:
Reflection
What did I learn from this? That I can use layers/names to find the correct gameobjects and manipulate only the ones that I want. This way you cannot throw different objects than clothing to Bob and have the system be confused. It also helped to make a class and I think I could implement that more often in my coding than I am doing now, it makes work easier. I also learned that sometimes the old way is still the best way. I still want to improve my system, because now you have to manually adjust all clothing that is attached to Bob to not have gravity etc. In the future I want it so that you have prefabs where you can attach a clothing model too and then it just works. This will also make it easier for people not familiar with Unity to work with it.