- Home /
How can I access Lightmapping settings for a light via script?
I need to change the value of a given light in my scene from lightmapping 'auto' to 'baked' via a script, but it is not currently exposed in the API - how can I do this?
Answer by OllyNicholson · Sep 05, 2011 at 03:51 PM
The lines of script you would need are :
Light go = o as Light;
SerializedObject serialObj = new SerializedObject(go); SerializedProperty lightmapProp = serialObj.FindProperty("m_Lightmapping");
lightmapProp.intValue = (int)lightmapping; serialObj.ApplyModifiedProperties();
Use this wizard script to test in the Unity editor
I am having trouble using this in javascript, the documentation examples are also C++ and if I use this code it complains about a missing ";"
Figured it out:
var serialLightSource : SerializedObject = new SerializedObject(spotlightObject);
var SerialProperty : SerializedProperty = serialLightSource.FindProperty("m_Lightmapping");
Answer by x4000 · Jun 26, 2016 at 09:10 PM
To add to the primary answer, this is is a super useful reference: https://github.com/MattRix/UnityDecompiled/blob/master/UnityEditor/UnityEditor/LightEditor.cs