- Home /
need help with a Ambiguous reference 'constructor'
This code is generating a Ambiguous reference 'constructor' error and I am unsure how to fix this.
var serialLightSource1 : SerializedObject = new SerializedObject(target.dynamicLightsource1);`
I$$anonymous$$HO it is bad practice to call the constructor of a SerializedObject (of any non-struct UnityEngine object as a matter of fact). What are you intending to do with it?
I am trying to acces the lightmap setting. I got this code here (my comments in that question) http://answers.unity3d.com/questions/163585/how-can-i-access-lightmapping-settings-for-a-light.html
$$anonymous$$y mistake. SerializedObject is the right thing to use if you wanna access hidden variables through Reflection.
$$anonymous$$y remarks about non-struct object is still right for UnityEngine but not for UnityEditor which SerializedObject belongs to.
Back to your issue:
What is the type of target.dynamicLightsource1? SerializedObject should only be used in editor classes.
Where did you type this line of code? If it is at a class level, note that you should never call constructor on class member declaration.
If you want to access lightmaps, you should use Light$$anonymous$$apSettings.lightmaps wich returns an array of lightmaps used in the current scene.
target.dynamicLightsource1 is dynamicLightsource1 on the target script the editor script is for, its a (point)light. I am changing its lightmapping setting from auto to baked only and that code was the only way I could do it in Unity 3.4
Answer by Kryptos · Jan 10, 2012 at 04:49 PM
SerializedProperty takes an object (of type Object) as parameter. There is no such property as dynamicLightsource1 in a instance of class Object. Therefore you need to perform a cast first.
Try this solution (here I assume that your script if of type Script):
var targetDynamicLight : Light = (target as Script).dynamicLightsource1;
var serialLightSource1 : SerializedObject = new SerializedObject(targetDynamicLight);
var serialProperty1 : SerializedProperty = serialLightSource1.FindProperty("m_Lightmapping")
Your answer
![](https://koobas.hobune.stream/wayback/20220613062823im_/https://answers.unity.com/themes/thub/images/avi.jpg)