Change "lightmappingMode" of a light per script.

Hi,

i would like to change the “lightmappingMode” of a directional light in runtime. I am using Unity 5.5.0p3 at the moment and targeting android.

I have tried something like this:

public class LightmappingModeSwitch : MonoBehaviour {

    public Light light;

    void Start ()
    {
        if (SettingsManager.instance.someBoolean) {                                
            light.lightmappingMode = LightmappingMode.Mixed;
        } else {
            light.lightmappingMode = LightmappingMode.Baked;
        }
    }
}

For some reason this is working on editor with this error:
Loading script assembly “Library/ScriptAssemblies/Assembly-CSharp-Editor-firstpass.dll” failed!

When trying to build for android i am getting this error:
error CS1061: Type UnityEngine.Light' does not contain a definition for lightmappingMode’ and no extension method lightmappingMode' of type UnityEngine.Light’ could be found. Are you missing an assembly reference?

Any help or another approach would be great.
Thanks!

When swapping to baked mode, the editor will try to bake the scene. This can only be done in Editor, as it is computationally expensive. Your script is trying to access a functionality that is only available within the Editor, which is why its throwing you the errors.

Hi, thanks for your quick response!
That’s bad :frowning:
My scene is baked of course but wanted to have the option to switch the lighting of my dynamic objects (characters) from baked light probes to realtime lighting with shadows. It was working in editor without any lag or problems, so i hoped i could do it in a build too :confused: