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 DocksonWedge · Oct 21, 2017 at 10:08 PM · load sceneupdate function

Stop Monobehaviour updates during LoadScene?

This is sort of a style question about some behavior that seems a little bit odd when I'm transitioning to a new scene. Specifically, this happens when the player dies and chooses to return to the main menu.

One note, the start menu is it's own scene, the in game pause/end menus are just prefabs Canvases with TimeScale=0;

Here's some pseudo code:

     LevelManager
     {
             if (playerHealth <= 0 && !displayingMenu)
                     {
                         PauseAndDisplayMenu(); //sets Time.TimeScale=0;
                     }
     }
     MenuButtonHandler
     {
         public void QuitToMainMenu()
         {
              OtherCleanup();
              Time.TimeScale=1;
              SceneManager.LoadScene(sceneNum);
         }
     }


This seems all well and good, except after LoadScene is called all of the update functions from the current scene are still running while the scene is loading. This gives LevelManager just enough time to run it's player health check again and set TimeScale back to 0.

Is this intended behaviour from MonoBehavior? It seems weird to continue to run update code in the transition between scenes. I could just stop this one script from running easily, but this could be a problem elsewhere too i.e. where globals or statics are set(not that I use them much), but the objects might be in a weird state.

I could also just stop any updates from running with monobehvior.enabled if I understand correctly and then re-enable it later. Or, I could try to move the unpause later, but I'm betting I'll have a hard time getting it in the right spot.

Is there any other way to stop these final few update calls? In my mind, if I'm calling loadScene in single mode everything should really stop, since that's the queue to change scenes, but maybe I'm thinking about it wrong.

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 Cuttlas-U · Oct 22, 2017 at 04:56 PM

hi; u can change this by create a simple bool ;

like : public bool IsPlayerDead = false;

so u make it true when player die;

then in update method in the first lane u dont let it to check any thing if its true like this:

 void Update()
 {
 
 if ( IsPlayerDead == true)
 {
 return;
 }
 }


then when game is starting again u can make it false again;

Comment
Add comment · Show 2 · 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 DocksonWedge · Oct 23, 2017 at 07:06 PM 0
Share

Sure, I'm using a similar thing as a workaround right now, but I don't like it from a defensive program$$anonymous$$g standpoint. This would need to be put in every update/late update/fixed update call I have to really seal off any strange behavior. I think it's just one right now that has a functional impact, but it would be nice to have a more elegant way to do this without managing a switch and hoping only a few update calls have any functional bugs.

avatar image Cuttlas-U DocksonWedge · Oct 23, 2017 at 07:15 PM 0
Share

this is a good way dont worry its not heavy on performance;

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

118 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

Related Questions

How to use UI button in Update()? 1 Answer

Beginner Question about triggering Update function 0 Answers

How to limit the amount of key presses that are read in the Update function? 0 Answers

After Editor Crash, Can't load any scene. 0 Answers

hi i need help by my project 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