Switching Materials On Command Ok, so here's the setup: I'm working on a model of a spaceship, using Cycles as the renderer. Eventually, this model may end up in a game (possibly under Unity or Unreal Engine). The ship has multiple light objects (running lights, cockpit lighting, etc.)

While the exact materials for each light will depend on the lamp, all will have materials for an Off/On state. Some lights may have multiple colors to indicate status (IE, the engine lights will have Off, Red, Amber, and Green depending on the engine's condition).

Right now, I'm selecting faces and manually applying the materials when I want to render lights off vs. on. Which is fine when I'm working in Blender and only want to adjust one light at a time. However what about when I actually try to bring this into a game engine? I may not be able to swap materials in and out in this manner. And is there a way I can dynamically switch between the On/Off state when working in Blender, especially once I begin rigging and animating the switches and toggles on the control panel?
You need to do all this on one material. Applying materials to individual faces is not going to work for rapid testing.

Once you are using only one material toggling On and off is easy and changing the color is super simple.

First off you will need a mask to differentiate what parts of the mesh will get what. I'd recommend using an image (easy to paint in texture paint mode and transferable to any game engine), but you can also use vertex colors, or proxy objects inside blender.

For my example I'm using an image, and vertex colors.

The image texture node is the mask I painted. The key to the toggling is the MixRGB node(s). The Value input node is what I'm using to control the toggling. When the value is 0 the MixRGB node is outputting 100% black, which is feed into the Fac for the Mix Shader node. (0 uses the top socket, 1 is the bottom socket) Likewise when the value is changed to 1,  the MixRGB outputs the mask image which has white painted in the proper places. Thus the Emission shader gets to shine.

Its the exact same thing for the one I have labeled "Engine toggle" except here I'm using the vertex colors as the mask instead of an image.

The RGB input is how I'm changing the color of the "lights." You could also use a image and a special UV map just to re color (You would simply move the UVs to a different color) but for in blender the node is much easier.



The nodes can look much neater when wrapped in a node group, but for testing I prefer access straight to the nodes.