Search Unity

  1. Unity 2019.1 beta is now available.
    Dismiss Notice
  2. The Unity Pro & Visual Studio Professional Bundle gives you the tools you need to develop faster & collaborate more efficiently. Learn more.
    Dismiss Notice
  3. We're looking for insight from anyone who has experience with game testing to help us better Unity. Take our survey here. If chosen to participate you'll be entered into a sweepstake to win an Amazon gift card.
    Dismiss Notice
  4. Want to provide direct feedback to the Unity team? Join the Unity Advisory Panel.
    Dismiss Notice
  5. Unity 2018.3 is now released.
    Dismiss Notice
  6. Improve your Unity skills with a certified instructor in a private, interactive classroom. Watch the overview now.
    Dismiss Notice

On Application Start function?

Discussion in 'Scripting' started by YevgenyBlinov, Dec 8, 2018.

  1. YevgenyBlinov

    YevgenyBlinov

    Joined:
    May 27, 2018
    Posts:
    4
    I need something to happen not on Start/Awake, and not when a scene is loaded, but only once the application is launched. It means that if I reload the scene, the function WILL NOT be called. PlayerPrefs doesn't work here too, because I DO want the function to be called again the next time the player launches the app. Is this possible?
     
  2. fire7side

    fire7side

    Joined:
    Oct 15, 2012
    Posts:
    1,810
    What I do is have a boot scene, which has what I want to stay persistent, and use DontDestroyOnLoad on the objects in the scene in the awake function, then I load the next scene which might be the menu or whatever. Don't know if that's what you mean or not. There is a video on persistence in the learn tutorials.
     
    Ryiah and Kurt-Dekker like this.
  3. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    3,146
    Yeah, this is definitely the winner way on Unity. Every one of my games has a "zeroscene" and it handles all the "I only want this to happen once" stuff.

    Alternately if you don't want to be reliant on going to a zeroscene every time you press play, you can implement one of the various ways of making Unity Singletons. Here's some more info on those:

    http://wiki.unity3d.com/index.php/Singleton
     
  4. orb

    orb

    Joined:
    Nov 24, 2010
    Posts:
    2,960
    MY starter scene is called "Init". I think a lot of developers use those :)

    It loads manager stuff, forwards to a menu scene or primary scene, and is never seen again until the app is launched again.
     
  5. YevgenyBlinov

    YevgenyBlinov

    Joined:
    May 27, 2018
    Posts:
    4
    Doing an init/boot/zero scene that won't be seen again, sounds like a great idea. :)
    This is exactly what I need.
    Thank you guys!
     
    Kurt-Dekker and Lurking-Ninja like this.
  6. Lurking-Ninja

    Lurking-Ninja

    Joined:
    Jan 20, 2015
    Posts:
    2,868
    Also if you want quick boot up, you can create a small temporary script, where you show a selector to select a level and upon start after the boot you can load that scene directly. So you keep the good things from both worlds, boot scene and "direct" play in a specific scene.
     
    Kurt-Dekker likes this.