Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
  • Help Room /
avatar image
0
Question by shadowpuppet · Feb 23, 2018 at 07:13 PM · loadlevelresetscriptingproblemrestart game

reloading a scene after death - resetting scripts

So I have a saved game. when I launch the editor and open my pause menu screen and hit "load saved" everything works as expected. I am where i was and all the playerPrefs have loaded. Now if I play and die, "game over" appears and I get thrown back to the beginning of the level - as I want. Problem is that if I hit "load saved" from the pause menu now - without quitting out of play mode in the editor - I do go where I am suppose to and some of the saved game info works but some doesn't. Bottom line is i have to quit out of PLAY mode in the editor and then go into play mode and load the save level then . I guess it has something to do with the void Start() functions? that when entering PLAY mode they get activated making the "Load Saved" work then, but if I die and go back to the start and hit "Load Saved" it doesn't work because the Start functions aren't restarting? I don't know. DOes this make sense and how can I load a save point without stopping play mode?. I imagine in a build this would amount to having to quit out of the game app and restarting it to load a save point successfully. How do I reset all my scripts after death as well player position?

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
3
Best Answer

Answer by Lilius · Feb 23, 2018 at 07:37 PM

Maybe you could reload the scene:

 using UnityEngine.SceneManagement;
 
     public void RestartScene()
     {
         Scene thisScene = SceneManager.GetActiveScene();
         SceneManager.LoadScene(thisScene.name);
     }

Then load saved game data. You might want not to destroy some of your scripts and objects, use DontDestroyOnLoad: https://docs.unity3d.com/ScriptReference/Object.DontDestroyOnLoad.html

Edit: Re-read the question and maybe this is what you are doing already? What happens when you die, do you reload the scene?

Comment
Add comment · Show 3 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image shadowpuppet · Feb 23, 2018 at 07:46 PM 0
Share

thanks....I actually stumbled onto something like this. I have a "restart" button in my pause menu as well - one i never even used until just a few $$anonymous$$utes ago. and after I hit the restart button and was taken back to the start of the level and THEN hit "Load Saved" it worked without having to quit out of play mode and all the code said was

 Application.LoadLevel(Application.loadedLevel);
avatar image Lilius shadowpuppet · Feb 23, 2018 at 07:53 PM 0
Share

Good. By the way, what version of Unity you are using? You should change that code to the one on my answer, because Application.LoadLevel is obsolete now and will not work if you update Unity.

avatar image shadowpuppet Lilius · Feb 23, 2018 at 08:12 PM 0
Share

I am using an ancient version 4.7. The game i am making is just a hobby that has been in the works off and on for a few years . I think I started in version 3. something. I have updated to 4.7 but that is as far as I go while working on this project. Tried not once but TWICE to upgrade to version 5 but it broke too many things - probably because of a lot of scripting code being obsolete - and simply not in the mood to back track and change code. Frankly a bit scared to upgrade even after I am done with this project as learning coding was a challenge and I'd hate to have to relearn the new changes. I have been making some changes just to eli$$anonymous$$ate some of the warnings. Like my graphics menu use to say QualitySettings.currentLevel = QualityLevel.Fantastic; and changed to the new and improved QualitySettings.SetQualityLevel(6);

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

130 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

How do I reset my game but keep the Player in the same position? 1 Answer

I need to fix a problem where my money resets when i continue to the next level 0 Answers

Retstart Key in C# or Javascript 1 Answer

Why is my unity trying to re import my game? 0 Answers

SetActive(false), and then back to true to call OnEnable 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges