- Home /
Script acces to a light its lightmode?
How can I modify the Lightmapping setting of a light its lightmode (baked only, auto, relatime only) from a script?
The documentation is not listing that variable.
Bluestrike: the link you've posted leads to a 404: not found
$$anonymous$$ay I ask if you are trying to build an EDITOR script? And if so, what are you trying to automate?
Its not a editor script, but I have one too and could do it from there as well. I have a lightpole prefab, in the editor the user can set it to on or off, switching between a self ilum material and a regular one, and changing the attached point light on and off as well.
There is also a selection: lightmaps only, lightmap-dynamic or dynamic. Dynamic is used to make the light switch on and off ingame, so it is not supposed to generate light from the lightmapper and I will need to set the light its lighmappermode to realtime only in that case.
Can you tell me what your final goal is that you are trying to achieve? I think you are approaching this incorrectly. Lightmap settings should be (iirc and understand what you're asking) in edit time only. Tell us what you're trying to achieve and I'll try to tell you how to do it.
I have a streetlight prefab that players can drag into the scene. The prefab has a script where I assigned different materials, one for when the light is off, one when the light in on, and one if the light is on but set to dynamic in a editor script (no emmision) and its only used in the editor to let the artists see if the lamp is on/off at the start. There are also references to the meshes and spot or point lights. and its those spot and point lights the lightmode i want to control from another script, only in the editor, but not nessesarily in a editor scipt. (I have the prefab script run in the editor)
To hide away all these things that should not be messed with I made a editor script. In the editor script the artist has the choice to set the prefab on or off, and a light mode for the streetlight prefab. (lightmap only, lightmap-dynamic and dynamic) When the artist shooses the dynamic mode it means the light will be turned on and off ingame, esle he should use the other options, And when he chooses the dynamic mode, I need to set the light its lightmode to realtime only ins$$anonymous$$d of auto.
Answer by Bluestrike · Sep 15, 2011 at 06:14 PM
This bas been brought to my attention: http://answers.unity3d.com/questions/163585/how-can-i-access-lightmapping-settings-for-a-light.html
Now my question is if its possible to do this without using serilaizedObject. But it appears to be the only way to have FindProperty() ?
Answer by BerggreenDK · Sep 13, 2011 at 08:51 AM
My answer guessing from all the commenting + your question would be NO you cant. But you should be able to archive the same effect with another approach:
Make the different states as separate prefabs. One for each state. Then when the user configures it to be another type. You could make an "empty" Prefab with a parent axis and then instatiate/spawn the choosen type within it. If the player/user selects another type just destroy the child object and spawn the new type.
Yeah but the idea of my script is just to avoid having many prefabs, I have 19 prefabs already and if I have to make 3 of eatch state for those its going to be alot ;)
Your answer
![](https://koobas.hobune.stream/wayback/20220612204837im_/https://answers.unity.com/themes/thub/images/avi.jpg)