Search Unity

How to change RenderSettings.skybox correctly in Unity5?

Discussion in 'Global Illumination' started by mechanic_kharkov, Sep 19, 2019.

  1. mechanic_kharkov

    mechanic_kharkov

    Joined:
    May 12, 2019
    Posts:
    9
    Hello All. There is a problem setting the skybox material at run time. I use this code to change it:

    RenderSettings.skybox = _skybox; //Material


    then as manual says I call
    Code (CSharp):
    1.  /* If you change the skybox in playmode, you have to use the DynamicGI.UpdateEnvironment function call to update the ambient probe. */
    2. DynamicGI.UpdateEnvironment ();
    But it does not update reflections. :-/
    It only resets reflections when I pass null as the new skybox material, And when later I set existing material back nothing happens (the skybox image changes, but the reflections don't exist anymore).

    I noticed that if I do it in editor, and then touch defaultReflectionMode (switch it to Custom, then back to Skybox), everything updates according to the new skybox. And in the status bar I see the message "1/3 Reflection probes | 1 jobs". But I do not use any reflection probes!
    I tried this in the script, but with no luck:
    Code (CSharp):
    1.     //touch the reflection type to accept the new skybox
    2.     RenderSettings.defaultReflectionMode = DefaultReflectionMode.Custom;
    3.     RenderSettings.defaultReflectionMode = DefaultReflectionMode.Skybox;
    It looks like it has some hidden reflection probe somewhere, and inits it when I set defaultReflectionMode = Skybox (manually).
    So, the question is - what function does it call to create this hidden probe, and is it accessible in the play mode?
    I've tried this in versions 5.2.4, 5.6.7 - same results.

    Now I'm totally lost. Is there a correct way to change the skybox material at runtime with correct reflections?
     
  2. kristijonas_unity

    kristijonas_unity

    Unity Technologies

    Joined:
    Feb 8, 2018
    Posts:
    1,080
    The attached script (DayNightCycle.cs) contains a very simple dynamic time of day system, which should work for your purpose. Check it out.
     

    Attached Files: