== Overview
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 [[ /w/mutable/unreal-engine-4/user-documentation/basic-concepts/ | Basic Concepts ]] page before start creating any Customizable Object
= Variate a hair’s mesh when a handkerchief is on
(NOTE) The resulting Customizable Object of this example can be found in the 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 [[/w/mutable/unreal-engine-4/examples/#village-demo | Village Demo ]] in //Content/HowTo/MaterialVariations// named "MaterialVariations"
== Steps
1) The first step is to create a basic [[ URL | Customizable Object]] asset with the Base Object, the Material and the Skeletal Mesh.
Image Step1
> 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 Child Object node and connect it to the “Children” connection of the Base Object.
Image Step2
---
3) In the Node Properties name this first object.
Image Step 3
> In this case, the child object’s name is Hair
---
4) From the “LOD 0” connection of the Child Object node create a Material node for this “hair” object.
Image Step 4A
With this last node selected go to the Node Properties tab and set the hair’s material.
Image 4B
> In this example, the material selected is “MaterialVariations_Hair_M”
---
5) Create a 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.
Image Step 5A
> In this case, the “MaterialVartiations_Hair” is chosen.
Afterward, link both “Mesh” connections of the Skeletal Mesh and the Material nodes.
Image Step 5B
---
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 Group node from the “Children” connection of the Base Object node to add the “handkerchief” object.
Image Step 6A
In the Node Properties tab, write a name for this group and choose the group type preferred.
Image Step 6B
> 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.
Image Step 7A
Name this object in the Node Properties tab.
Image Step 7B
> In this case, the group’s name is “Handkerchief” and the type is “Toggle”.
---
8) From the “LOD 0” connection of the Child Object node drag and drop to create a Material node.
Image Step 8A
Set the handkerchief’s material in the Node Properties tab.
Image Step 8B
> 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.
Image Step 9
> In this case, the mesh selected is “MaterialVariations_Handkerchief”.
---
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.
Image 10A
To fix this, a Material Variation node has to come into play. First of all, a tag to identify which is the object 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, unfold the Tags sub-tab.
Image Step 10B
Create a name for this tag.
Image Step 10C
> 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 Material Variation node.
Image Step 11
---
12) With the Material Variation node selected, go to the Node Properties tab and add a new variation by clicking the “+” button.
Image Step 12A
Unfold the “0” layer sub-tab under Variations and write the same name written on the handkerchief material’s tag previously.
Image Step 12B
> 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 hair’s material and skeletal mesh to the “Default” connection of the Material Variation node.
Image Step 13
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.
Image Step 14
---
15) The Material node should be the same as the default hair’s one, but the mesh is different.
Select the varied hair mesh Skeletal Mesh node and set the corresponding mesh in the Node Properties tab.
Image Step 15
> 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.
Image Step 16
---
17) Compile. Compare how the hair looks without the handkerchief and then enabled it. Notice the differences between the meshes.
Image Step 17A
Image Step 17B