Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

How is Light.lightmapBakeType an editor-only property?

Discussion in 'Editor & General Support' started by dgoyette, Jan 9, 2020.

  1. dgoyette

    dgoyette

    Joined:
    Jul 1, 2016
    Posts:
    4,120
    I get bit by this every once in a while, and only much later when I do a build. Apparently, the lightmapBakeType property on LightmapBakeType is editor only. The documentation clearly states this (https://docs.unity3d.com/ScriptReference/Light-lightmapBakeType.html), but there's no indication of that in Visual Studio. In addition, it's really surprising that this is the case, since the property is in a class under the UnityEngine namespace (not the UnityEditor namespace), and the enum is also in UnityEngine.

    So, a couple of questions:
    • How is it that this class actually is editor-only, without requiring a UnityEditor include, and without being in a class that is in the UnityEditor namespace?
    • Could it be made not to be this way? It's pretty obnoxious to have a property like this, which results in the code compiling fine when in the editor, but failing in a build.
    • Is there a non-editor-only equivalent I can use to find out whether a given light is dynamic or baked? The similar LightmappingMode property is deprecated.
     
  2. kromenak

    kromenak

    Joined:
    Feb 9, 2011
    Posts:
    266
    It's unclear how the lightmapBakeType field is made to be editor only. It may simply be a #if UNITY_EDITOR preprocessor around that property. I don't see a preprocessor in the assembly browser, but then again, I don't believe the assembly browser would show preprocessors!

    If you look at the Unity install, you'll notice that there are several versions of "UnityEngine.dll" for different platforms. So, it seems reasonably that the version used for the editor may include that function while non-editor versions do not.

    It seems unlikely that Unity would change this unless there were a lot of complaints!

    I noticed that lights have a field called "bakingOutput" - with subfields of "isBaked" and "lightmapBakeType" - maybe you could use those at runtime? If I had to guess why two versions of that field exist, I'd imagine it's because you might change the property on the light, but not bake it. So, the editor-only one is the desired bake type for the future, whereas the version in the output struct is what the lights settings currently are, based on the most recent bake.
     
    dgoyette likes this.
  3. dgoyette

    dgoyette

    Joined:
    Jul 1, 2016
    Posts:
    4,120
    Thanks, baking output does seem to have the data I was after, so I'll use that. I just wish it wasn't so easy to accidentally use the wrong one here. Maybe Unity can update their class documentation so that mousing over the property gives some warning that the field is editor-only. /shrug.
     
  4. paxron

    paxron

    Joined:
    Aug 22, 2014
    Posts:
    8
    Thank you @kromenak, I also naturally gravitated towards finding all real-time lights using
    Light.lightmapBakeType.RealTime. But bakingOutput.isBaked works instead for build purposes.