About : How to change a material in-game.
Target Audience : Unreal Engine users - Intermediates
Platform : Unreal Engine 3
Last Update : January 2008
Its use
The ability to change a material in real time can be used for a large number of situations:
This tutorial will quickly talk you through the process on how to set up an instanced material. For additional information you may also want to read the bit on Instanced Materials in my third material tutorial.
Setting it up
Create a new material, and add a TextureSampleParameter2D (=Parm2D) expression instead of a regular TextureSample. Fill in your texture into Parm2D expression, as if it were a regular TextureSample, and also be sure to set a ParameterName. The name will be used to identify all the expression in Kismet and the Material Instance later, so pick something descriptive.



Open Kismet, and add two Set TextureParam's.

Preferably also add a Trigger actor, or Triggervolume, to the level, and also add it to Kismet. Set the whole thing up like shown in following screenshot.

The second Set TextureParam is similar, but it uses the original texture as its NewTexture.
If you were walk into the trigger, the material would change to the new texture, and change back to the original as soon as you leave the trigger's radius again.
The trigger should also have its MaxTriggerCount set to 0, so it is infinitive.
You can use this technique for just about anything. You could delete the second Set TextureParam so it only changes the texture just once. You could hook up a timer so you can time exactly when to change the texture. You could base the switch on whether or not the player is carrying the CTF flag. Etcetera.








