Changing the material of a ShapeBase object using script
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.
Getting ready
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.
How to do it...
Use the ShapeBase setSkinName()
method to change an object's materials. To modify an object from using base_
materials to team1_
materials, make the following method call (with the object referenced using the %myObject...