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 DewDrop · Nov 27, 2012 at 01:20 PM · levelrestartlevel load

while i restart the game,it hangs. why so?

 var restart=GUI.Button(Rect(30,145,200,50),"restart");
 if(restart)
     {
     Application.LoadLevel(1);
     }

This is my code snippet. I tried to restart my scene then the game hangs.I had no idea why it behave so,also tried "Application.LoadLevelAdditive(1);" but no good.

Do anybody have an idea why my game hangs while it restarts?

Comment
Add comment · Show 8
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 Psymon · Nov 27, 2012 at 01:22 PM 0
Share

In your BuildSettings (Ctrl + Shift + B), does your scene have the id 1 ? Do you have any bug reported in the console ?

avatar image DewDrop · Nov 27, 2012 at 01:29 PM 0
Share

yes the loading scene has an id 1. i have 3 scenes, first main menu then game_part and last one is score card. i need to invoke the game part when it restarts. the game_part loads it self when it restarts.

avatar image DeveshPandey · Nov 27, 2012 at 01:30 PM 0
Share

Check your console, and let me know if any warning or error.

avatar image DewDrop · Nov 27, 2012 at 01:33 PM 0
Share

DeveshPandy , actually when i restart. the whole editor hangs :-)

avatar image Psymon · Nov 27, 2012 at 01:38 PM 0
Share

$$anonymous$$aybe it's because Application.LoadLevel() is called multiple times. Try to put a Debug.Log() in the condition ins$$anonymous$$d of the Application.LoadLevel to check.

Show more comments

3 Replies

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

Answer by DewDrop · Nov 29, 2012 at 01:32 PM

hi all, thanks for your help. At last i figure out my problem. the problem related to STATIC variables. i made static variables as state flags. one of my static variable remains in false state that triggers the PAUSE command. then when the scene restarts the game hangs without a warning.

once again thank you all.

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 darknessfell · Nov 18, 2017 at 09:27 PM 0
Share

How to do it? I’m having the same problem

avatar image DewDrop darknessfell · Nov 20, 2017 at 01:14 PM 0
Share

first, you check how many static variables you are used. then check each one's usage. if you use static variable flags for boolean flags. check time scaling zero on scripts start or awake. hope you will find an answer. here the topic is too old. cheers.

avatar image
0

Answer by MonsterLobster · Nov 27, 2012 at 02:05 PM

That is because once you push the button the variable doesnt reset and keeps loading the scene (if your object is set to not get destroyed on load). Maybe use this:

 var restart=GUI.Button(Rect(30,145,200,50),"restart");
 
 if(restart)
 {
 Application.LoadLevel(1);
 restart = !restart;
 }



I guess this will fix it. Hope it helped!

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 DewDrop · Nov 29, 2012 at 01:34 PM 0
Share

thanks $$anonymous$$onsterLobster, i tried your method. but don't work at last i understand that the problem was actually related with static variables. it needed to reset some variables before loading the same scene.

avatar image fafase · Nov 29, 2012 at 01:38 PM 0
Share

Actually the restart resetting will not happen since the scene is already reloaded.

avatar image
0

Answer by DeveshPandey · Nov 27, 2012 at 02:45 PM

This will solve your problem. :)

 if(GUI.Button(Rect(30,145,200,50),"restart"))
 {
     Application.LoadLevel(1);
 }
Comment
Add comment · Show 4 · 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 DewDrop · Nov 29, 2012 at 01:35 PM 0
Share

hi DeveshPandey, the problem was related with static variables. thank you.

avatar image DeveshPandey · Nov 29, 2012 at 02:17 PM 0
Share

You are most welcome, DewDrop, but which static variable, here not used any.

avatar image DewDrop · Nov 30, 2012 at 03:25 AM 0
Share

DeveshPanday, at first i thought the problem is due to this portion because it happens only when i restart the game. after i tried many method suggested by friends here like you and others i fond that the source of problem is somewhere else. then i figure out the right reason is uncleared static variables.

avatar image DeveshPandey · Nov 30, 2012 at 04:24 AM 0
Share

Ohk, fine enjoy :)

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

16 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

Related Questions

I need to restart scene on collision ( when ball hits bottom wall), but this code doesn't work . What should I do ? 1 Answer

Resetting a Scene 2 Answers

Level Not Loading After Screen Fade 1 Answer

Application.LoadLevel not Resetting 2 Answers

Next Level to unlock when first level is completed 2 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