Full Character Customization With Morphing in Unity (Body Features and Hair)

Providing a character customization UI, enables me to create and customizer any game character, using morph targets, and custom scripts in Unity.

This UI provides the capability to permanently *(for the duration of the game) to change facial features, body mass, hair styles, brows, mustaches, beards and their colors via a custom written UI.

The morph targets were created in Max, and were auto generated from scripts for the accessories (hair, beard etc. *clothing and armor too coming soon) using the morph trargets of the base character, which were created manually, to alter the facial and body features of the character.

This will also allow great freedom in creating more unique looking characters for games, from base characters, and to allow the player to customize his character to look unique, and different to anybody else.

The development workflow can be seen, and is pretty well documented here:

The morph scripts work by exporting the base objects (character or accessory) as a skinned/skeletal mesh (FBX), and then by exporting the morph targets for each, as a separate FBX, each skinned mesh, will have it’s own FBX, with all of it’s morph targets in, the morph targets are exported with only vertex ,UV and normal information, and imported into Unity as MeshFilters.

The system then creates a snapshot, of the morph target vertices, and determines which vertices by index, are actually influenced by this morph, and the rest is destroyed, so the morph targets are never part of any rendering pipeline, only the vertex and index information is kept.

This information is then used to selectively and additively morph the base skinned mesh, but this morph does not happen on every update loop, only if something changes, because this type of morphing is not facial animation, for eg, this is exactly what I want, the morph will only happen as changes occur, and only affected vertices are influenced, and only once are the vertices updated when to the skinned mesh when everything has been calculated, this has proven to be extremely efficient.

Unity also has a bit of a draw back when it comes to changing vertices on skinned meshes, it does not expose a ‘mesh’ property for skinned meshes, only a sharedMesh, the sharedMesh is shared across all skinned meshses, that were created from the original FBX, which means, even if you break the prefab instance of the skinned mesh, and then morph it, when you stop unity, the skinned mesh is now changed, if you were to save the scene, it would persist that information permanently, and this is not what you want when creating multiple unique characters from the base.

In one of my documents I mention a possible solution, to import multiple FBX, but that is not a solution at all, the solution was in the end, to clone the sharedMesh, and replace the sharedMesh property, on the skinned mesh renderer, and this effectively cloned and broke that link.

Meaning any morph changes done, are no longer affecting the skinned mesh original sharedMesh,   but the system does cater for the fact that, maybe instancing is what you want, and will allow you to override that, but that is usually not a good idea.

Another problem that still needs solving, is generating tangents for normal mapping, and not loosing the ability to morph, when Unity is asked to generate or import tangents, it becomes a problem, also, if Max split’s normals, it also does not work, therefore scripts were created to facilitate this using MAXScript, and has proven invaluable and extremely time saving.

More to come soon, for clothing and armor, also facial animation will be in the pipeline for constant morphing, that technique will be different than the customization technique, in that it will constantly need to update the mesh vertices, which can be done very effectively, using Unitys MakeDynamic() call, before updating.


The GUI in action.


Leave a Reply