Skip to content

Instantly share code, notes, and snippets.

@redseiko
Created October 20, 2024 00:36
Show Gist options
  • Select an option

  • Save redseiko/fa0be6a43f918b4bc891ef5a5c9968b0 to your computer and use it in GitHub Desktop.

Select an option

Save redseiko/fa0be6a43f918b4bc891ef5a5c9968b0 to your computer and use it in GitHub Desktop.

Revisions

  1. redseiko created this gist Oct 20, 2024.
    34 changes: 34 additions & 0 deletions ResetLightingDataAsset.cs
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,34 @@
    using UnityEditor;
    using UnityEditor.SceneManagement;

    using UnityEngine;
    using UnityEngine.SceneManagement;

    [InitializeOnLoad]
    public static class ResetLightingDataAsset {
    static ResetLightingDataAsset() {
    EditorSceneManager.sceneOpened += OnSceneOpened;
    }

    // Create an brand new Scene and swap to it first to get this assigned.
    // TODO: just get the asset via hard-coded string.
    static LightingDataAsset _builtinLightingDataAsset;

    private static void OnSceneOpened(Scene scene, OpenSceneMode mode) {
    Debug.Log($"Scene: {scene.name} opened.");

    Debug.Log($"LightingDataAsset is: {Lightmapping.lightingDataAsset}");

    if (Lightmapping.lightingDataAsset) {
    Debug.Log($"Path: {AssetDatabase.GetAssetPath(Lightmapping.lightingDataAsset.GetInstanceID())}");

    if (!_builtinLightingDataAsset) {
    _builtinLightingDataAsset = Lightmapping.lightingDataAsset;
    }
    } else if (_builtinLightingDataAsset) {
    Debug.Log($"Setting to builtin one");
    Lightmapping.lightingDataAsset = _builtinLightingDataAsset;
    EditorSceneManager.SaveScene(scene);
    }
    }
    }