Search Unity

Resolved Manual Application freeze

Discussion in 'Scripting' started by stychu, Mar 22, 2021.

  1. stychu

    stychu

    Joined:
    May 9, 2016
    Posts:
    62
    Hello there,

    I have a database that I would like to load on before everything else.
    Database Init call has an OnComplete callback which will get executed once the database is loaded.

    Can I somehow manually stop/freeze the application until I get that OnComplete action fired off?
     
  2. Brathnann

    Brathnann

    Joined:
    Aug 12, 2014
    Posts:
    7,187
    If no other code is executing, then it's simply going to wait till the OnComplete is called to continue if you setup your code that way.
     
    Joe-Censored likes this.
  3. Joe-Censored

    Joe-Censored

    Joined:
    Mar 26, 2013
    Posts:
    11,847
    The easy way would be to do your database stuff in a loading scene. Once it completes, then you load into your main game scene. That way none of the scripts in the game scene need to be written to wait for the database load to complete.
     
    Sphinks, stychu and Brathnann like this.
  4. stychu

    stychu

    Joined:
    May 9, 2016
    Posts:
    62
    Yeah exactly what I was thinking of. That would easily work with the build but how I tackle this in the play mode. Should I have a scene manager that always loads up the zero scene and switches to the one I'm working on?
     
  5. Brathnann

    Brathnann

    Joined:
    Aug 12, 2014
    Posts:
    7,187
    Normally if I need to test data with a loading scene I either just switch to the loading scene and hit play or if I'm happy with the loading scene, I just toss in some local test data that can be loaded from any other scene as if I started play mode from the loading scene.
     
    stychu and Joe-Censored like this.
  6. Joe-Censored

    Joe-Censored

    Joined:
    Mar 26, 2013
    Posts:
    11,847
    Yeah I just switch to the loading scene first as well. I've seen a few threads on the topic of creating your own system to detect you're starting in the wrong scene, and automatically switch to the first scene.
     
    stychu likes this.
  7. stychu

    stychu

    Joined:
    May 9, 2016
    Posts:
    62
    Cool thank you guys for the suggestions! Much appreciated!
     
    Kurt-Dekker likes this.