Search Unity

Question Forcing Graphics Redraw?

Discussion in 'General Graphics' started by Zullar, Jul 21, 2020.

  1. Zullar

    Zullar

    Joined:
    May 21, 2013
    Posts:
    651
    tldr; Is there a way to force an immediate graphics redraw?


    I have a splash screen that I use several places during scene/asset loading times. Code is something like this.

    Code (csharp):
    1.  
    2. SplashScreen.enabled = true;
    3. LoadStuff(); //This takes a few seconds
    4. SplashScreen.enabled = false;
    5.  
    However the SplashScreen is NOT shown during loading (likely due to Render only occurring at the and of the Frame which it doesn't reach due to being stuck in LoadStuff() method)

    What I would like to do is force a graphics redraw here
    Code (csharp):
    1.  
    2. SplashScreen.enabled = true;
    3. FORCE_REDRAW();
    4. Load(); //This takes a few seconds
    5. SplashScreen.enabled = false;
    6.  
    Is there any way to force a graphics redraw? Canvas.ForceUpdateCanvases() and Camera.main.Render() do not work.

    Thanks in advance.
     
    Last edited: Jul 22, 2020
  2. FurkanSz

    FurkanSz

    Joined:
    Dec 27, 2019
    Posts:
    9
    Maybe I am misunderstanding this, but couldn't you do what you want by using a coroutine and waiting for the next frame to call the Load method?

    Code (CSharp):
    1.    
    2. splashScreen.enabled = true;
    3. StartCoroutine(LoadWrapper());
    4.  
    5.  
    6. private IEnumerator LoadWrapper()
    7.     {
    8.         yield return null;
    9.         Load();
    10.         SplashScreen.enabled = false;
    11.  
    12.     }
     
    Zullar likes this.
  3. Zullar

    Zullar

    Joined:
    May 21, 2013
    Posts:
    651
    I think what you posted would work. I may have to go with that.

    I've been trying to avoid asyncloading or co-routines or frame delays because can cause un-robust problematic code if you aren't careful.

    Thanks though.
     
    Last edited: Jul 22, 2020
  4. jamespaterson

    jamespaterson

    Joined:
    Jun 19, 2018
    Posts:
    400
    Hi. FYI I ended up using a similar approach for my loading screen, i.e. coroutine to wait before loading. Kinda silly there isn't a better way to do this IMHO
     
    Zullar likes this.