Material slots

Models can use multiple materials. You can set the materials in the model's material slots.

For example, the second material slot in this model specifies the material for the visor and the shoulder and chest plate stripes. By changing the material in this slot, we change the material used in these parts of the model.

Materials

The material slots themselves — their number and position — are defined in the model source file (eg , , etc). You can't edit material slots in Game Studio; you can only change which materials are used in each slot.

You can change the materials a model uses in two places:

  • Under the Materials properties of the model itself:

Note

This affects every instance of this model.

  • In the model component of an entity or prefab:

Model materials on entity

This only affects this instance or prefab.

Models imported from modeling software can contain meshes. Meshes can share materials via material slots.

The association between a mesh and a material slot is defined in the model source file. You can't change these associations in Game Studio, but you can change them in code at runtime.

To change the association between a mesh and a material, use:

To change or add a material to the list of materials:

When Xenko draws a model with meshes, it performs one GPU draw call for each mesh. By default, to improve performance, at build time, Xenko merges meshes that share materials.

In the example above, there are five meshes and five draw calls. After merging, there are three meshes and three draw calls.

Note

When Xenko merges meshes, it merges the vertex and index buffers. This means you can't draw the meshes separately at runtime, and you can't change the original mesh position (transformation matrix). The meshes become a single mesh with a single material and a single transformation matrix (relative to the model).

Note

When Xenko merges meshes, it changes the draw order of elements. In the case of transparent materials, this can produce different results.

Note

When you create a , Xenko builds separate convex hulls for each mesh in the model. If the meshes are merged, only one mesh remains per material, so convex hulls are also built from merged meshes.

Disable mesh merging

You might want to disable mesh merging if you want to:

  • animate a mesh

To disable mesh merging on a model:

  • In the Property Grid, disable Merge meshes.

Disable merge meshes

Disable merging for specific meshes

To disable merging only for specific meshes, enable their corresponding nodes.

  • Select the model that contains the meshes.

  • In the Property Grid, under Skeleton, make sure the model has a skeleton associated with it.

For more information about skeletons, see Animation.

  • In the Asset View, select the skeleton.

Select model skeleton

  • In the Property Grid, under Nodes, select the nodes that correspond to the meshes you don't want to merge.

Tip
Note

Make sure you don't disable nodes that are animated at runtime.