Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

Variables won't reset after scene load

Discussion in 'Scripting' started by rhyvon, Mar 8, 2015.

  1. rhyvon

    rhyvon

    Joined:
    Dec 9, 2014
    Posts:
    4
    I'm working on a little racing game. After you finish the race you can choose another track of reset the current track / race. I'm having some problems with loading other scenes or reloading the scene, most of the variables are not resetting. For example the ranking (position) in the race is displayed and lap times etc.
    When i go to another scene the positions / ranking from all the players are still there?!

    I'm not using any static vars or dontDestroyOnLoad stuff so that's not the problem..
    Really stuck on this problem :(

    They way i'm loading another scenes is like this: (using the number of the scene from build settings)
    Code (JavaScript):
    1. function ChangeToScene(sceneToChangeTo : int)
    2. {    
    3.     Application.LoadLevel (sceneToChangeTo);
    4. }
    It should reset all variables, but i isn't...
    Any help would be great!! :)
     
  2. SunnySunshine

    SunnySunshine

    Joined:
    May 18, 2009
    Posts:
    955
    Are you using static variables? They won't reset.
     
  3. rhyvon

    rhyvon

    Joined:
    Dec 9, 2014
    Posts:
    4
    As mentioned above, i'm not using any static vars of dontdestroyonload