Search Unity

  1. The Unity Pro & Visual Studio Professional Bundle gives you the tools you need to develop faster & collaborate more efficiently. Learn more.
    Dismiss Notice
  2. Want more efficiency in your development work? Sign up to receive weekly tech and creative know-how from Unity experts.
    Dismiss Notice
  3. Participate with students all over the world and build projects to teach people. Join now!
    Dismiss Notice
  4. Build games and experiences that can load instantly and without install. Explore the Project Tiny Preview today!
    Dismiss Notice
  5. Improve your Unity skills with a certified instructor in a private, interactive classroom. Watch the overview now.
    Dismiss Notice
  6. Want to see the most recent patch releases? Take a peek at the patch release page.
    Dismiss Notice

On Application Start function?

Discussion in 'Scripting' started by YevgenyBlinov, Dec 8, 2018 at 11:20 PM.

  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,775
    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:
    2,877
    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,950
    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 LurkingNinjaDev like this.
  6. LurkingNinjaDev

    LurkingNinjaDev

    Joined:
    Jan 20, 2015
    Posts:
    1,756
    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.