4 – Working with MICs and Materials

(For this tutorial, I am using the 2012-10 version of the UDK, and the assets available through it. Assets and materials belong to EPIC )

“What are Material Instance Constants (aka MICs), and why would I use them?”

MICs are references of another material- called a master material- that have some parameter values changed. Let’s say you’re creating a material for a light. As you set up the material for it, you could add in a color adjustment to make the emissive be a warm yellow color.

Relatively simple set up, showing the Texture Sample, the Emissive Mask, and the Color that we're applying to the light.

Relatively simple set up, showing the Texture Sample, the Emissive Mask, and the Color that we’re applying to the light.

Now let’s say that you want another light that uses the same mesh, but on this light you want the emissive to be red. You could make two materials for each. Alternatively, you can add in parameters in one material, dictating what color the light is. Now, instead of having two materials, you have 1 material, and a copy that you can tweak values on. MIC LightTut 2 MICs give you the same visual quality of the master material, let you see changes in the editor without having to recompile the whole material, and allow you to change how assets look based on events in-game. Also, because they are cheaper memory-wise, they allow you to have multiple variations of one material, without paying the cost of duplicating that original material over and over. In short, it’s like creating a 1:1 hologram, instead of a straight-up clone. All of the visual information is there, without the added cost.

“How do I make a Master Material?”

Master materials are no different from regular materials. You don’t even have to name it as a ‘Master’, but that does come in handy if you have to wade through lots of MICs and Materials later to find it. You will, however, need to add in your parameters. There are a few ways to set up parameters: one easy way is to right click on a node, and then select convert to parameter. Be sure to name it, so that when you edit your MIC later you know exactly what you’re altering. This also helps prevent you from accidentally changing values on multiple nodes that have the same name, especially if you leave them all as ‘None’. The Parameter “Group” name dictates where in the MIC window your parameter is located. It’s useful to set group names on large and complex materials, but it’s not necessarily needed on smaller ones. MIC LightTut 3 The other way to add parameters is to learn the hotkeys for adding nodes. It makes workflow be just a little bit faster, and makes changing materials quickly be easier. Some (not not all) hotkeys include:

  • 3 + leftclick = constant 3 vector (used for color changes, etc, and shown above)
  • v + leftclick = parameterized 3 vector (for quick color changes in MICs)
  • 1 + leftclick = constant 1 vector
  • S + leftclick = parameterized 1 vector
  • T + lefclick = Texture sample
  • L + leftclick = Lerp node
  • A + leftclick = Add (math) node
  • M + leftclick = Multiply node
  • U+ leftclick = Texture coordinate
  • C + leftclick = Mask (R/G)

It’s worth noting that not every node can be parameterized on its own. Texture coordinates, which control texture tiling, are one such examples, but there are ways to isolate numbers and make those values editable. It just takes a bit of setup.

“How complex can my master material be?”

Materials can get to be pretty complex, based on what they’re being used for, and what you want them to do. If you know you’ll be getting a lot of use out of it, then it’s okay to set a lot of parameters that you can quickly change. Remember, the more complex the material, the more likely you should use Group Names for your parameters to differentiate between Emissive Params, Diffuse Params, Normal Params, etc.. Let’s go back to our light’s master material. This time, we want to add in an option for it to change from yellow to red, and an additional option for it to turn off completely. To make this work, we’ll be using a lerp (linear interpolate) node to switch between what we want to happen in our light. In the below example, I’ve set up a LERP function with 3 parameters: EMI_Color_A, EMI_Color_B, and EMI_Color_Switch. Here, the switch acts like a boolean. When Switch is set to “0”, then Color A shows up. When Switch is set to “1”, Color B shows up. MIC_LightTut_5   We then create a second LERP, which tells the material to either have the Emissive be on or off. In this case, we want “0” to be on, and “1” to be off. I’ve used a Constant 1 Vector here, as that will make the Emissive “mask” show as having nothing, and will give us the proper “this light is turned off” effect. MIC_LightTut_6

“I’ve got my material set up. How do I get it to animate in game?”

If you want game events to alter how your materials look, we’ll need to use actor classes, MICs, and a bit of Kismet matinees. First, create a MIC for your material. Next, go to the Actor Classes tab in your browser, and find a “Material Instance Actor” class. Where it’s sorted may change depending on your version of Unreal. You can always search for it in the browser window if need be.

MIC_LightTut_7

You can either drag-and-drop the actor into the play space, or right-click in the game world and select “Add MaterialInstanceActor Here” With your actor selected, hit F4 to bring up its properties window. Make sure your MIC is selected in the Content Browser, then assign it to your Actor by clicking the little green arrow.

MIC_LightTut_8

Now, select the mesh in your level that you want to change. For this demonstration, I’m using StaticMesh’HU_Mech.SM.S_HU_Mech_SM_Light’, which is a light found in the UDK’s “HU_Mech” environment package. Hit F4 to bring up the properties of your mesh. Expand Static Mesh Actor -> Static Mesh Component -> Rendering. Under ‘Materials’, click on the green plus to add a material slot, and then use the green arrow to assign your MIC to the mesh. Voila! These are the basic steps to get everything in place.

In Kismet- Make sure that your Material Instance Actor is selected in the editor when you open Kismet. Right-click on the grey space, then select “Create Matinee.” Double click your new Matinee, and you’ll be presented with the Matinee editor. Right-click in the dark grey space, then select “New Empty Group” and name it. I’ve named mine “MIC_Color_Control”. Right-click on your new group, then select “Add New Float Material Param Track”. This will give us the track that lets us control our MIC’s parameters.

Here’s the important part: On that Parameter track, you MUST specify what Parameter you’re calling and changing. A lot of times, if you duplicate a matinee, it’ll reference old Parameter Tracks and Parameter Names. You’ll have to delete the extras, and make sure you’re only calling what you want. Sometimes it’s easy to forget this step altogether, and your MIC changes won’t show at all in game. For this track, we’ll call the EMI_Color_Switch param.

Now you can start adding in your keyframes! Add one at 0.00 seconds, and another at 1.00 seconds. Your values for these should be 0 by default. On your second keyframe though, right-click, and select “Set Value”. Change the value from 0 to 1. You should see your mesh in-game automatically change to the second emissive color. If it’s not, check to be sure the proper MIC is actually assigned to the mesh, and that you specified a parameter for the track to control. You can set up a second matinee the same way, but instead of calling “EMI_Color_Switch,” you’ll want to call the “EMI_Toggle” Param. In the game, I’ve set the first Matinee to change based on a trigger volume. The light will turn red if players are inside the volume, and will switch back to yellow if the volume is empty. The second Matinee is set on a looping switch, and is fired using a regular trigger (press ‘E’ to use the trigger). This turns the light on and off.

End Notes:

You don’t have to make MICs be animated. Sometimes they’re just used to change the scaling on a material, change the color of an object, or change an image stamp on a mesh. Also, there are a plethora of other things that can be done with Materials, and this tutorial is just a general introduction to show how they can be used in a play space. If there are any questions, please comment below. I’ll try to answer as best as I can, or provide more tutorials to help.

 

I’m including the map file that I created this tutorial in, if people want to have a look. It does  use the light from Epic’s asset package, and that may or may not show up. You can click here to download the file