While a game is running we may want to modify the materials used by an object based on some event. For example, in a base-capture game we want the base's flag to show the current team's colors. This process of changing an object's materials is called changing an object's skin in Torque 3D. In this recipe we will modify an object's materials at any time using TorqueScript.
Modifying an object's materials while a game is running is very similar to skinning using the World Editor. In preparation for this recipe, please see the How to skin an object in the World Editor recipe in Chapter 2, Working with Your Editors, and set up all of the materials and the object to be skinned as described there.