Search Unity

Question Lighting doesn't update immediately, when changing Shadowcaster. (HDRP)

Discussion in 'Global Illumination' started by Jonny010, Jun 2, 2023.

  1. Jonny010

    Jonny010

    Joined:
    Feb 16, 2019
    Posts:
    7
    So I'm not very knowledgable about lighting, but this behaviour seems weird to me. I try creating a day-/night cycle and swap the Light.shadows from Soft to None between sun and moon. Weird thing is, the lighting updates in a wrong way, when swapping from sun to moon.

    How it looks like:


    How it's supposed to look like (updates correctly, once I move something in the scene):


    Here's the code that's causing problems (called from OnValidate()).

    Code (CSharp):
    1.     private void DayTransition()
    2.     {
    3.         if (this.timeOfDay > 6 && this.timeOfDay <= 18)
    4.         {
    5.             if (this.moon.shadows != LightShadows.None)
    6.             {
    7.                 this.moon.shadows = LightShadows.None;
    8.                 this.sun.shadows = LightShadows.Soft;
    9.             }
    10.         }
    11.         else
    12.         {
    13.             if (this.sun.shadows != LightShadows.None)
    14.             {
    15.                 this.sun.shadows = LightShadows.None;
    16.                 this.moon.shadows = LightShadows.Soft;
    17.             }
    18.         }
    19.     }