In-game Custom Characters / Items, how is it done?

A lot of modern games now have some form of in game character / item creator, I’ve looked around and I’d like the communities input on how it might be best to approach this situation using Unity. Looking at the example project from Unity this is how I think their project works:

  • Both character models are imported as .FBX files which contain the mesh broken into the separate pieces
  • Textures are set out in a way to switch in out of an assigned material to change an objects colour
  • Scripts call different objects to be drawn and hide others depending on buttons pressed through the GUI

I can’t even begin to read the code so I have no idea how the scripts work. My main concerns are that the end model has so many materials for it because each custom piece requires it to switch in the new textures to change a colour without effecting the rest, this goes against the “Use no more then 3 materials” for an optimized character tip.

Does anyone have experience with this or links to any articles regarding how other studios do it?

The no more than 3 materials refers mainly to a object, not “customized character” which the material count can get much higher because of the sum of all materials on many objects(which is acceptable). It would be pretty difficult to use under than amount of materials on say a custom spartan in Halo Reach. In reach I assume each add on is a separate model. Just as the gun is attached to their hands, the armor is attached to specific armor points.

In Unity this means each separate object is at least one draw call. Perhaps using the Mesh.CombineMesh() function will help by making it read as part of the single player object when not in customization mode where each object would have to be separate.

But yes, you are correct, each add on to the base player is another object, so games like WoW can have a player with 5 or more materials because of boots chest armor gloves helmets base character and weapons. Also, even though a mesh might have 20 optional components or textures, Unity will load only what it needs and discard what it doesn’t. So say you have a piece of armor that uses two materials, one for the cloth portion and one material for the metal portion. So the cloth is dull and the metal is shinny and they use two different materials. So you want to change the color of the metal, you swap out the texture on that material. The object still only has 2 materials. Say you want to make the metal part a different metal which is more rough etc. You swap the metal material. The object still only uses 2 materials and still only renders 2 materials and the textures used on those materials. The only real cost of having the add-ons is VRAM and that you need to optimize texture sizes and scenes so you can have a room full of the highest polygon/material count add-ons on the max number of people you want to have on screen. It’s no different than adding regular objects to the screen, except that they are attached to the player.

This quote makes everything make more sense now regarding optimizing draw calls. Do you know how you might handle the repeated texture work? Like changing the base colours of an item surely shouldn’t have to be repainted by an artist for each colour right. Would a shader be able to be made so that a colour picker determines base colours on a texture determined by designated areas set out by an artist?

For changing colors on textures, it could be done in a few ways. One is having multiple textures and each is a color variant. This technique is easy to do in Photoshop or GIMP if you know how to use layers and think about making the texture multiple colors from the beginning. Then you just modify the color layer and save each color vairant and allow the user to select a color based on the pallet you have chosen. A stand out franchise for me is Halo. The original had different textures for each color. Same with Halo 2. Although in Halo 2 they had 2 textures for their model allowing you to change Primary and secondary color. Each color set was premade. Easy to swap easy to code into a game engine.

Another way you can do it in Unity is using the “main color” property in the material details section of the inspector. This will give an overall color to the object and is a cheap and easy way to give some color variance. This however will distort colors and it becomes very obvious of how it was done. This technique was used in Vigilante 8 Second Offense to allow the user to choose the “color” of their car. Because of the color chosen and how it blends with the previous texture, there is a very limited variance in colors to choose from.

The last way I can think to do color changes is to make your own shader(code it or use those nifty node based editors that are floating around here on the forum). It’s the same idea as the first one, except instead of making the color choice and saving the image, the shader can do it for you. You would want to make shader that would take a “detail map” that would be rendered on top of a “color map” Now both those words I just invented, so let me explain further. The detail map would contain any details such as baked shading, scratches special color spots(a logo that wont change color for example) and would be added into the texture on top of the color map. The detail map may also need an alpha layer so it can be properly super imposed on the color map below. The color map is basically what it sounds like. Its a texture that is nothing more than RGB color. It does not have to be a texture, but must output color as the base for the “detail map” to be placed on to. Then by manipulating the shaders “color map” it should only change the color of the selected part of the texture. The details will then remain crystal clear and look as if each possible RGB value is a texture in itself.

All of this was done off the top of my head, but it sounds reasonable and logical to me.
To be honest I am looking to do the same thing in my game. Perhaps this could be a new community asset? I won’t be able to play with shaders for a bit but if I were to make one I would upload it for everyone to use. I will definitely be using a shader as the answer to my color picker design.

Thanks again for your detailed response. I assumed the exact same approach using photoshop / GIMP but for anything offering a lot of customization this I would think is a very slow way to deal with the issue. I think a clever shader would work perfectly, I wonder if the node based shader I’ve see in the showcase section would do the trick?.. If not then I’d be interested funding what I can to have one developed, maybe start a thread in the collaboration section like what was done for the GTA car driving scripts.

Your really on a role with this. Any opinion on how exactly morph targets are done to effect a character height/weight/muscles etc?

My guess is that a lot of extra work would go into modelling each end of the scale for every required option, so a really tall and a really short character for height, really thin and a really fat character for weight and again a really muscular and no muscle definition version of the character. Morph target/blend shape type code would then scale between the meshes based on certain conditions. Problem is if you had add-on items like clothing and such you wouldn’t just need to model one jacket for example but six if you wished to use the three options above. Two jackets modelled to fit each end of the scale for each option… This seems again like a lot of work but for this I have no idea of any other solution that could be used.

Well for clothing on top of a character, remember in the real world the only difference between clothes is scale. This means that theoretically, you should be able to model one jacket and scale its x/y/z to fit each character. If it doesn’t seem to fit just right, then I would say it would add another layer of realism as cloths never fit the same on two different people. Worst case scenario is that the arms might need to be separate so then can scale separate from the bulk of the jacket. However, I know with the mesh deformation script floating around the forum it is possible to isolate vertices and move them. So you could have a collider that encases all of the vertices for each arm and then use a modified version of the script to deform it.

I am assuming then there are three ways to animate something like a jacket. One way is to do it on the base model of the jacket. This may lead to issues later on in game if you are allowing the player to scale the player infinitely as the jackets arm may not scale to fit right or finding the proper scaling might be incredibly difficult. Remember close enough is good at the current scale, if you have the pc up scale or downscale those nice looking proportions might be way off. Another way is to use cloth simulation which is expensive on current technology. The last option is to put some bones in the jacket and make it a ragdoll model. I am not sure if you can adjust or scale bones after they are loaded into Unity, but the cheapest way to animate a jacket would be to create some sort of rag doll system that could have the joints match up with the players skeleton.

I am not familiar with morph targets, but I would assume that morphing animations together would be the most strait forward approach for the muscle animation. If you would be creating this level of detail it might become necessary to chop up the model into chunks so the computer has to do less blending while running and shooting for example. If its one model it would have to blend the shoot animation with run and also blend the two muscle animations together for both running and shooting. If the arms are separate there are less calculations as in run mode the arms are swinging but while shooting they are up right holding a weapon. So keeping legs, torso, arms and head/neck as separate models combined might increase performance as there is less blending per frame the pc would have to do.

Again this is all theory. I have not had experience completing these tasks as such, but I do know that all of these techniques are currently used by the big name developers. Although usually its only a few of these at a time.

Sources: Countless articles on game design I have studied over the years.