This article explains how to trigger the activation of a mesh variation when a certain object is enabled by setting up a tag in its Material node and using it as well in a Material Variation node. In this case, the mesh switch is between the original hair of a character and a variation of it that fits properly when wearing a handkerchief.
(WARNING) The Material Variation node allows showing different meshes, morphs, materials or textures when a certain object is active.
(WARNING) We recommend visiting the [[ mutable/unreal-engine-4/user-documentation/basic-concepts/ | Basic Concepts ]] page before start creating any Customizable Object
= Hair’s mesh variation when a handkerchief is on
(NOTE) The resulting Customizable Object of this example can be found in the [[mutable/unreal-engine-4/examples/#village-demo | Village Demo ]] in Content/Examples/HowTo/ Material Variations named "Material Variations"
== Assets required
* One material asset or material instance of the character without parameters (textures included)
* One skeletal mesh of the character with the previous material applied (one material, no parameters)
* One hair mesh
* A head’s handkerchief
* A variation of the previous hair mesh adapted to the handkerchief
(NOTE) The resulting Customizable Object of this example can be found in the [[mutable/unreal-engine-4/examples/#village-demo | Village Demo ]] in //Content/HowTo/MaterialVariations// named "MaterialVariations"
1) The first step is to create a basic [[ mutable/unreal-engine-4/user-documentation/create-a-basic-customizable-object/ | Customizable Object]] asset with the Base Object, the Material and the Skeletal Mesh.
> In this example, the **Customizable Object** asset is named "Material Variations", the **Reference Skeletal** is "MaterialVariations_BaseBody", the **Material** is called “MaterialVariations_M” and the **Skeletal Mesh** is the same as the Reference Skeletal’s one.
2) To begin with, the default hair mesh has to be added to the character. To do so, create a [[mutable/unreal-engine-4/user-documentation/nodes/child-object/ | Child Object]] node and connect it to the “Children” connection of the **Base Object** node.
3) In the Node Properties name this first object.
> In this case, the child object’s name is "Hair".
4) From the “LOD 0” connection of the **Child Object** node create a [[mutable/unreal-engine-4/user-documentation/nodes/material/ | Material]] node for this “hair” object.
With this last node selected go to the Node Properties tab and set the hair’s material.
> In this example, the material selected is “MaterialVariations_Hair_M”.
5) Create a [[mutable/unreal-engine-4/user-documentation/nodes/skeletal-mesh/ | Skeletal Mesh]] node to add the hair’s mesh. In the Node Properties tab, select the default hair’s mesh from the //Skeletal Mesh// sub-tab drop-down menu.
> In this case, the “MaterialVartiations_Hair” is chosen.
Afterward, link both “Mesh” connections of the **Skeletal Mesh** and the **Material** nodes.
6) Now, the hair is created as a constant resulting object, but in the case of the handkerchief, it is more effective to have the option to enable and disable it to see how the switch between the two hair’s meshes works.
Create a [[mutable/unreal-engine-4/user-documentation/nodes/object-group/ | Group]] node from the “Children” connection of the **Base Object** node to add the “handkerchief” object.
In the Node Properties tab, write a name for this group and choose the group type preferred.
> In this example, the group’s name is “Handkerchief” and the type is “Toggle”.
7) Now, create a **Child Object** node and link its “Object” connection to the “Objects” one of the **Group** node created previously.
Name this object in the Node Properties tab.
> In this case, the group’s name is “Handkerchief” again.
8) From the “LOD 0” connection of the **Child Object** node drag and drop to create a **Material** node.
Set the handkerchief’s material in the Node Properties tab.
> In this example, the material selected is “MaterialVariations_Handkerchief_M”.
9) Finally, create a **Skeletal Mesh** node to add the handkerchief’s mesh. In the Node Properties tab, set the corresponding handkerchief’s mesh.
> In this case, the mesh selected is “MaterialVariations_Handkerchief”.
Link the "Mesh" connections of both **Skeletal Mesh** and **Material** nodes.
10) Currently, both objects are already set, but if enabled at the same time, they don’t match each other. Compile if wanted to check it.
To fix this, a **Material Variation** node has to come into play. First of all, a tag to identify which is the object's material that triggers the switch between the default and the varied mesh is needed.
Select the **Material** node of the “handkerchief” object and in the Node Properties tab, click the "+" button on the //Tags// sub-tab.
Create a name for this tag.
> In this example, the tag is called “Handkerchief”
11) Afterward, go to the “Hair” **Child Object** node and disconnect it from its **Material** node making some room between them. Drag and drop from the “LOD 0” to create a [[mutable/unreal-engine-4/user-documentation/nodes/material-variation/ | Material Variation]] node.
12) With the **Material Variation** node selected, go to the Node Properties tab and add a new variation by clicking the “+” button.
Unfold the “0” layer sub-tab under //Variations// and write the same name written on the handkerchief material’s tag previously.
> In this case, the tag is also called “Handkerchief”
(IMPORTANT) The name of the tag must be exactly the same, if not, the activation of the object whose material has a tag won’t trigger the modified mesh.
13) Connect the previously disconnected hair’s material and skeletal mesh to the “Default” connection of the **Material Variation** node.
This is the mesh that will be displayed as default if the handkerchief is not enabled.
14) Finally, it is time to add the modified hair mesh. From the “Variation 0” connection of the **Material Variation** node create a **Material** and a **Skeletal Mesh** nodes (the same structure as the Default’s one) or just duplicate the “Default” ones.
15) The **Material** node should be the same as the default hair’s one, but the mesh is different.
Select the varied hair mesh's **Skeletal Mesh** node and set the corresponding mesh in the Node Properties tab.
> In this example, the mesh chosen is “MaterialVariations_HairHandkerchief”
16) Finally, the nodes’ structure is finished. Verify that the Source Graph tab looks like the image below.
17) Compile. Compare how the hair looks without the handkerchief and then enabled it. Notice the differences between the meshes.