Unity-Technologies/UnityCsReference · error · Exception
Lightmapping.lightingSettings is null. Please assign it to a
Error message
Lightmapping.lightingSettings is null. Please assign it to an existing asset or a new instance.
What it means
Lightmapping.lightingSettings getter throws a plain System.Exception when the backing LightingSettings asset is null. Rather than returning null, Unity forces callers to assign a LightingSettings instance (a new one or an existing asset) before reading the active settings. A non-throwing TryGetLightingSettings(out var) overload exists for code paths that may run before settings exist.
Source
Thrown at Editor/Mono/GI/Lightmapping.bindings.cs:539
[StaticAccessor("GetLightmapSettings().GetReadOnlySharedData()")]
public static extern bool HasDynamicGILightmapTextures();
public static bool TryGetLightingSettings(out LightingSettings settings)
{
settings = lightingSettingsInternal;
return (settings != null);
}
public static LightingSettings lightingSettings
{
get
{
var settings = lightingSettingsInternal;
if (settings == null)
{
throw new Exception("Lightmapping.lightingSettings is null. Please assign it to an existing asset or a new instance. ");
}
return settings;
}
set
{
lightingSettingsInternal = value;
}
}
[StaticAccessor("GetLightmapSettings()")]
[NativeName("LightingSettings")]
internal static extern LightingSettings lightingSettingsInternal { get; set; }
[StaticAccessor("GetLightmapSettings()")]
[NativeName("LightingSettingsDefaults_Scripting")]
public static extern LightingSettings lightingSettingsDefaults { get; }
View on GitHub (pinned to 225b0fbdb5)
Solutions
- Assign settings first: Lightmapping.lightingSettings = new LightingSettings(); (or an existing asset).
- Use the non-throwing overload: if (Lightmapping.TryGetLightingSettings(out var s)) { ... } else { s = new LightingSettings(); Lightmapping.lightingSettings = s; }
- Ensure the scene's referenced LightingSettings asset is not deleted/null.
Example fix
// before
var s = Lightmapping.lightingSettings;
// after
if (!Lightmapping.TryGetLightingSettings(out var s))
{
s = new LightingSettings();
Lightmapping.lightingSettings = s;
} Defensive patterns
Strategy: validation
Validate before calling
LightingSettings s;
if (Lightmapping.TryGetLightingSettings(out s))
{
// use s
}
else
{
s = new LightingSettings();
Lightmapping.lightingSettings = s;
} Try / catch
try { var s = Lightmapping.lightingSettings; }
catch (System.Exception) { Lightmapping.lightingSettings = new LightingSettings(); } Prevention
- Prefer TryGetLightingSettings over the throwing getter in code that may run before settings exist.
- Always assign a LightingSettings in bake automation/CI before reading it.
- Do not delete the LightingSettings asset a scene references.
When it happens
Trigger: Reading Lightmapping.lightingSettings in a fresh scene/project with no lighting settings asset; after the LightingSettings asset was deleted or cleared; in batchmode/headless bake automation that never assigned one.
Common situations: New scene before any lighting settings were generated; deleted the LightingSettings asset from disk; CI bake script that jumps straight to reading settings.
Related errors
- index must be between 0 and {albedoTexturePropertiesCount -
- index must be between 0 and {emissiveTexturePropertiesCount
- index must be between 0 and {transmissiveTextureCount - 1},
- index must be between 0 and {transmissiveTexturePropertiesCo
- index must be between 0 and {GetCookieCount() - 1}, but was
AI-assisted analysis of Unity-Technologies/UnityCsReference@225b0fbdb5 (2026-08-13).
Data as JSON: /api/errors/1c7c1a5358b2e296.
Report an issue: GitHub.