Creating and using Material Instances.

Having to create, setup, and tweak standard Materials can be a very time consuming process in UE4. To help speed up and streamline this process, Unreal Engine 4 offers a special type of Material called a Material Instance. In the following How-To, you will learn to setup and use Material Instances in your projects.

Material Instancing

Material Instancing is a way to create one single Material, referred to as the Parent Material, that can then be used as a base to make a wide variety of different looking Materials. To achieve this flexibility Material Instancing uses a concept called inheritance. Inheritance simply means that properties that the parent has are given to the children of that parent. Here is an example of Material inheritance in action.

Material_Instancing_Explanation.png

Number Explanation
1: This is the Parent Material that the two Materials Instances you see to the right inherit their properties from. Also take notice that there are four Textures used in the Material.
2: This is where the Material that should be used as the Parent Material is set in the Material Instance. Changing the Material that is used here can completely change how the Material Instance works.
3: By changing the Textures used here, you can change the entire look of the Material Instance. Notice how there are four Texture inputs here, those four inputs are there because the Material Instance inherited that functionality from the Parent Material on the left.

Material Parameters

In order to be able to change the various parameters of Material Instances, you have to use a different kind of node in the Material Graph called a Parameter Node. A Parameter Node looks and works like a regular Material Expression node but its key difference is that, Parameter Nodes are used for telling Material Instances how to function. Using Material Parameters is the only way to get a Material to interact with a Material Instance.

Adding / Converting nodes into Parameters nodes

You can add Parameter Nodes to the Material Graph in two completely different ways.

  • Adding from Material Palette - If you do a search using the word, Parameter in the Material Palette you can find all of the Parameter nodes that are available. You can then Drag & Drop these nodes from the Palette to the Material Graph.

    Materails_Instances_Search_For_Pram_Nodes.png

  • Converting a Node - When inside of the Material Graph, you can Right-Click on a node and the choose the Convert To Parameter option like so.

Keep in mind that you cannot do this for every Material node. If you do not see the Convert To Parameter option when you Right-Click on a node, then that node cannot be converted into a Parameter Node.

Creating a Material Instance

In the following section, we will be creating our very own Material Instance using the methods mentioned above.

  1. The first thing that we need to do is create a new Material to work with. To do this, Right-Click in the Content Browser and then select Material from the Create Basic Assets list to create a new Material.

    Materails_Instances_Creat_New_Material.png

  2. With the Material now created, let us name the Material. For this example, the Material has been named Material_Master

    Materails_Instances_Named_Material.png

  3. With the Material now named, locate it in the Content Browser and then Double-Click on it with the Left Mouse Button to open it up. Once opened, search for the following Material Expression nodes in the Palette and add them to the Material Graph.

    • Constant 3 Vector x 1

    • Constant Node x 1

    • Scalar Parameter x 1

  4. Now that the Material Nodes have been placed down, it is now time to wire them up to the their respective slots in the Main Material Node. For this example, we will be using the following slots.

    • Base Color

    • Metallic

    • Roughness

  5. Once everything has been hooked up, it is now time to convert some of the material nodes into Parameter Nodes so that they can be used in Material Instances . To do this, Right-Click on the Material node that you want to convert and then select Convert to Parameter from the Right-Click menu.

  6. Now that we have our nodes converted to Parameter nodes, it is now time to label them so that when we use them in a Material Instance, we will know what each node does. To give a Parameter node a name select the Parameter node in the Material Graph with the Left Mouse Button and then under the Parameter Name section type in a name that you want to use as the Parameter Name. For this example, we will be using the following names.

    • Base Color

    • Metallic

    • Roughness

    Make sure that the name that you pick for your node matches very closely to what the node actually does. This way you do not have to keep going back and forth between the Material and Material Instance to see what the node actually does.

  7. Once the nodes have been made, make sure to compile your Material by pressing the Apply button. If compiled correctly, the Apply button should be grayed out like the following.

    Materails_Instances_Complied.png

  8. Now that the Material has been compiled, it is now to time make a Material Instance out of it. To do this, Right-Click on the Material in the Content Browser and then select the Create Material Instance option.

    Your Material Instance will derive its name from the Material that you are using to create it from. You can re-name the Material Instance during creation time or by selecting the Material and pressing F2 on the keyboard and then entering the name you want it to have.

  9. To open the newly created Material Instance use the Left Mouse Button and Double-Click on it in the Content Browser to open it up. When open, you should see something that looks like this.

    Materails_Instances_Instance_Editor.png

  10. Once you have the Material Instance Editor open, you can then start to adjust the parameters to your liking. To adjust a parameter, you first need to enable it by clicking on the box that is to the left of the parameter name to enable it. Once a parameter has been enabled, its name will no longer be grayed out and a check mark will be placed in the box to the left of the name.

  11. Now that the parameters have been enabled, you can now adjust any of them and see the results in real time, all without having to re-compile the Material.

The names that you set for parameters inside of the Material reflect the names that you see inside of your Material Instance. This is why it is very important that you pick names that correspond to what the parameter actually does. Materails_Instances_Names_Relation.png

Material Instances in Action

The full power of the Material Instance system comes into play when you need to have lots and lots of Materials that look different but still have similar controls or if you need to control a Material in a specific way during game play. In the following example, we will make three different Instanced Materials that are based off of the Parent Material that was created in the previous steps. We will then change the Parent Material to show how changes to the Parent will affect the Children.

  1. First we are going to need to make some more Material Instances using the Material_Master Material that was created above as the Parent Material. To do this, use the Mouse to Right-Click on the Material_Master in the Content Browser and then select Create New Material Instance from the menu. Do this two more times until you have a total of three Material Instances.

    Materails_Instances_Create_3_New_MI.png

  2. Now with the three additional Material Instances created it is time to open them up and begin adjusting their Parameters. To open one of the Material Instances up Double-Click on it with the Left Mouse Button inside of the Content Browser. Once open you can then set the Color, Roughness, and Metallic values to meet your needs. For this example, we are using Red, Green, and Blue as the colors with various numbers for the other inputs. You can see all of the numbers used for this example in the image below.

  3. With our Material Instances created and filled in with some data we can now apply them to objects in the world. For this example, we will be applying the Material Instances to some basic meshes that can be found in the Shapes folder of the Starter Content.

  4. Now to see the full power of the Material Instance system in action, open up the Master_Material. Once the Master_Material is open select one of the Scalar Parameter Nodes and duplicate it by pressing CRTL+ W on the keyboard. Now that the node has been duplicated rename it to Specular and set the default value to 0.5. Connect the output of the Scalar Parameter node to the Specular input and then compile the Material.

  5. Once the Material has been compiled, you can close down the Master Material and then open up the Red Material Instance. Once opened, notice how there is now a new input for Specular. Now check both the Blue and Green Material Instances, notice how they both now have new inputs for Specular. This is where the real power of the Material Instance lies, Changes that you make to the Parent Material will always be propagated to their children.

Changing a Material Instance's Parent Material

You can quickly change the Material that is used as a Material Instances parent by setting a new Parent in the Material Instance editor. To do this, all you have to do is open the Material Instance and then in the Details Panel under the General section, change the Material that is in the Parent section to a new Material of your choosing. After doing this, depending on the options of the new Material, the Material Instance Editor will change to reflect the options of that new Parent Material. Here is a Material Instance that was created using the Material from above as its Parent.

Material_Instancing_Change_Parent.png

Here is that same Material Instance but this time with the Parent Material changed. Notice how there are fewer Texture inputs and some new numeric inputs have been added.

Material_Instancing_Change_Parent_Results.png

Conclusion

Material Instancing is a powerful tool that can be used across all aspects of your project. From helping to add some variation to weapons and props to helping artist make better use of available Materials, Material Instances can really help to streamline and unify how Materials are created and used in your project.

Tags