I am trying to make a basic "light bar" type thing, where a switch turns it on and off. I have the two materials created (one emissive and one not). They work as expected if I set them at design time -- the emissive one lights the room and the other one doesn't. However, when I try to use my switch and light code to make the material switchable, the emission doesn't work. The material changes to the glowing, brightly colored one, but the lighting in the room doesn't change at all.
This is the code I'm using to change materials (which is working, it's just not including the emission of the new material, if applicable):
if(Ship.lights) {
GetComponent<MeshRenderer>().material = on;
} else {
GetComponent<MeshRenderer>().material = off;
}
This is similar to another question on SO (Unity emission isn't updating when I change the material) but this guy seems to be changing his existing material to be emissive, whereas I'm switching to an emissive material. Just for fun I tried adding his suggested line (reproduced below) and it had no effect.
mat.EnableKeyword("_EMISSION");//This is a bug in unity
I'm assuming I either need to tell Unity to recalculate the lighting in the scene, or do something else when I change the material to make the object emissive. Thoughts? I am admittedly very new to 3d modelling so it's very possible I'm trying to do something the wrong way.
CodePudding user response:
You need to go to the material and set it to realtime (probably your material is in bake mode)