Skip to content

Instantly share code, notes, and snippets.

@dimmduh
Last active December 21, 2022 09:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dimmduh/016d59a72e22f2cda5bfd98f76ea2ad4 to your computer and use it in GitHub Desktop.
Save dimmduh/016d59a72e22f2cda5bfd98f76ea2ad4 to your computer and use it in GitHub Desktop.
Unity fix dark scene after scene loading (skybox, reflection probe)
using System.Collections;
using UnityEngine;
using UnityEngine.Rendering;
//https://forum.unity.com/threads/solved-scenemanager-loadscene-make-the-scene-darker-a-bug.542440/#post-7752681
public class z_DarkSkyboxFix : MonoBehaviour
{
IEnumerator Start()
{
if (RenderSettings.customReflectionTexture != null)
{
yield break;
}
var baker = gameObject.AddComponent<ReflectionProbe>();
baker.cullingMask = 0;
baker.refreshMode = ReflectionProbeRefreshMode.ViaScripting;
baker.mode = ReflectionProbeMode.Realtime;
baker.timeSlicingMode = ReflectionProbeTimeSlicingMode.NoTimeSlicing;
RenderSettings.defaultReflectionMode = DefaultReflectionMode.Custom;
yield return null;
DynamicGI.UpdateEnvironment();
baker.RenderProbe();
yield return new WaitForEndOfFrame();
RenderSettings.customReflectionTexture = baker.texture;
Destroy(gameObject, 1f);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment