blog games developers documentation portfolio gallery

Documentation:

CombineMeshes()

Mesh[] GameObject.CombineMeshes()


Mesh[] CombineMeshes(string[] skipSubmeshNames, bool makeNewGameObjectWhenRendererPresent = true)



Extension to GameObject class
Collects alle skinned meshes and non-skinned meshes in any of the child gameobjects of the target, including the mesh of the target itself (if it has one).

When you provide an array of names of child gameObjects, those gameObjects will not be included in the merge. When the array is null or empty, all children will be merged

When the optional parameter makeNewGameObjectWhenRendererPresent is false, the default behaviour is overruled, where a new gameObject would be created when the original gameObject already contains a renderer component. (see examples below)

Examples:
MergeThis (no renderer)
-- child (has renderer)
-- child (has renderer)
Will change the gameobject like this:
MergeThis (has renderer)
-- child (disabled)
-- child (disabled)

makeNewGameObjectWhenRendererPresent = true (default behaviour)
MergeThis (has renderer)
-- child (has renderer)
-- child (has renderer)
Will change the gameobject like this:
MergeThis (disabled)
-- child (disabled)
-- child (disabled)
And create a new gameObject like this:
MergeThis_merged (has renderer)

makeNewGameObjectWhenRendererPresent = false
MergeThis (has renderer)
-- child (has renderer)
-- child (has renderer)
Will change the gameobject like this:
MergeThis (has renderer)
-- child (disabled)
-- child (disabled)

if only non-skinned meshes are found


Combines all meshes in to 1 new mesh.
Deactivates the child gameObjects that contained the original meshes

if 1 or more skinned meshes are found


Combines all skinned meshes in to 1 skinned mesh
Deactivates the child gameObjects that contained the original skinned meshes
Next combines any non-skinned meshes in to the merged mesh.
Deactivates the mesh renderers in the gameObjects that contained the original non-skinned meshes. The transforms of those gameobjects are added to the bone structure.

The bones structure of the merged mesh will contain the bones of all child meshes. plus an additional bone for each non-skinned mesh
The bindposes of the merged mesh are copied from the the first occurence of a bindpose for the bone.
The vertices of meshes with bindposes that differ from the already processed bindposes, will be remapped to fit the merged bindposes.

if number of vertices > 64K


Unity has a limit of 64K vertices. To overcome this, the mesh will be split into 2 or more parts. For each part a child gameobject is added.






follow us