Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 /
avatar image
0
Question by ChrisHorrigan · Jan 28, 2014 at 05:42 PM · sceneloadnullapplicationrestart

Restarting a Scene

This is the desired flow for my game: you start in the menu and press space to go to the game, you press space in the game scene to play, you press space when a player has fallen to get back to the menu, you press space again in the menu to go to the game scene again, you press space to play in the game scene BUT I now get an error when setting everything to 'enabled'

MissingReferenceException: The object of type 'Player2' has been destroyed but you are still trying to access it. Your script should either check if it is null or you should not destroy the object. Player.gameStart () (at Assets/Players/Player.cs:45) GameManager.triggerGameStart () (at Assets/GameManager.cs:16) GameManager.Update () (at Assets/GameManager.cs:31)

This is the code in the Game scene that causes the transition to the menu. The first space bar condition is the one that starts the game if you're at the beginning waiting to play, and the second condition is for getting back to the menu after a player dies.

 void Update(){
             if (Input.GetKeyUp ("space") && !isRunning&&!hasRun) {
                             //    print ("space was hit");
                             triggerGameStart ();
                             isRunning = true;
                     }
             if (Input.GetKeyUp ("space") && !isRunning && hasRun) {
                 print ("hit space");
                 StartCoroutine(swapScene ());
                     }
         }
     IEnumerator swapScene(){
             print ("called method");
             yield return new WaitForEndOfFrame();
             Application.LoadLevel("MenuScene");
             }

Before it threw an error about player two, it was complaining about a piece of text. I was able to fix the text problem like this (in text manager):

  void gameStart(){
             if(startInfo!=null)
             startInfo.enabled = false;
             }

So it moved on to finding a problem with player. I don't know why things are being considered "destroyed" because my code does not destroy these things, merely disables them and enables them depending on if the action is currently on. When I transition from the menu to the game for the second time, I want it to pretty much start up all the GameScene scripts as if for the first time, because the game scene runs just fine the first time. What is happening differently when I load the level again?

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
0

Answer by getyour411 · Jan 29, 2014 at 07:22 AM

As you move from scene to scene, things that dont have DontDestroyOnLoad are wiped. I think this is what you are missing

http://docs.unity3d.com/Documentation/ScriptReference/Object.DontDestroyOnLoad.html

Comment
Add comment · Show 1 · 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 ChrisHorrigan · Jan 29, 2014 at 01:22 PM 0
Share

Well for this I actually want everything to be wiped. When I transition from game scene to menu scene after somebody dies, I want all the game stuff gone to be set up anew once I transition from menu to game once again. So as it stands right now, everything is getting destroyed from game scene when a player dies as it takes me back to the menu. When I reload the game scene, shouldn't it put everything back in its original position, run the Start methods again, etc.? I just want it to launch the game scene as if it's the first time, every time.

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

18 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

Related Questions

Click Object to change scene 2 Answers

LoadLevelAsync - Stops Randomly? 1 Answer

Loading player location in a scene 2 Answers

HELP Game Scene 8 (-1) Cannot be loaded because it has not been added to the build settings 1 Answer

Restarting scene not working properly 1 Answer


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