Hi, I have tried using material.EnableKeyword(“_EMISSION”); to toggle the emission checbox on my standard shader, but it stays unchecked,
I do see the emission texture gets enabled after calling the above command, but still the checkbox is not checked, and when I click on the material the emission dispersal.
How do I properly set the emission checkbox from c#?
The Emission UI is enabled by looking at the material’s global illumination flags. The default, and disabled state, is: MaterialGlobalIlluminationFlags.EmissiveIsBlack
To enable the checkbox the value needs to be set to RealtimeEmissive, BakedEmissive, or somewhat counter intuitively None.
The None flag just means the emissive color doesn’t affect global illumination, not that there’s no emissive, where as EmissiveIsBlack means there’s no emissive, hence why it’s used as the disabled state.
I am using 2018.4.22f1 and just enabling the _EMISSION keyword worked fine for me. I was mislead by bgolus’s response and only tried setting the globalIlluminationFlags, but that didn’t work.
Thank you for the answer! I have no idea why Unity mentions nothing about this in Material Document.
Using 2020.3.25f1, material.EnableKeyword(“_EMISSION”) didn’t set the checkbox in inspector, nor did material.DisableKeyword(“_EMISSION”).
This feels like a bug…
To enable a material’s Emission property, try using
Just thought I’d note that only material.EnableKeyword/DisableKeyword(“_EMISSION”) worked for me on Oculus Quest (and android target). I could otherwise get it to work fine in the editor. But only that bit of code made it work right in the built apk.