I am making an infinite racing game where you fly an airplane while trying to avoid obstacles. I recently finished my menu that comes up when you die. When I press the restart button that simply reloads the current scene like this: SceneManager.LoadScene(1); it gives me a weird result. The obstacles starts generating at about the same position as you died previously. I never get this problem when I start the game with the Unity play button. The only thing I could think off was player prefs. It should not affect the generation of obstacles but tried anyway to use: PlayerPrefs.DeleteAll(); before reloading the scene, but that did not work. What could be causing this strange problem?

  • 1
    \$\begingroup\$ Might be good to include code relating to your scene reloading and also your obstacle generation scripts. I suspect the issue is that your obstacle generator is persisting through the scene reload, so it's remembering the previous position of the player. Its reference to the player may not have been updated to the new player, so it keeps polling the position of the old one with its old values. \$\endgroup\$ – Adam B Dec 2 '19 at 22:18
  • \$\begingroup\$ I only used one line to reload the scene and it is this one: SceneManager.LoadScene(1); \$\endgroup\$ – christian Dec 3 '19 at 7:55
  • \$\begingroup\$ Found the issue, one variable was static apparently that causes problems \$\endgroup\$ – christian Dec 3 '19 at 8:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.