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
1
Question by ryf9059 · Jun 17, 2013 at 02:42 PM · editorcrashdebug

How to stop editor from running a dead loop.

I made some logic error which caused the game to run into an infinite loop and the editor freezes and don't take any of my input. Is there a way to stop it or insert a break point during the dead loop process? Now I can only use task manager to kill it.

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

5 Replies

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

Answer by Veehmot · Jun 17, 2013 at 10:07 PM

There isn't, but you can force a break in the code using Debug.Break.

This is useful when you want to check certain values on the inspector and you are not able to pause it manually.

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 Jamora · Jun 17, 2013 at 10:14 PM 0
Share

A nice find, but you would still need to somehow know when a loop is stuck before calling Debug.Break(). $$anonymous$$aybe by using a timer?

avatar image Veehmot · Jun 17, 2013 at 10:16 PM 1
Share

You know how it's done usually in other environments, by using a counter inside a while loop, and if that counter is greater than an arbitrary number, you stop the execution.

avatar image bubzy · Jun 17, 2013 at 10:20 PM 0
Share

yeah, this is a nice method.

avatar image
1

Answer by Jamora · Jun 17, 2013 at 08:10 PM

There is no way to resume an unresponsive Unity editor that I know of. But as a way to prevent your editor from freezing in the first place, always place all while loops (and others that could potentially get stuck) in a coroutine.

Comment
Add comment · 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
0

Answer by bubzy · Jun 17, 2013 at 03:07 PM

take the loop out of your code.

check to see if theres some way you can use an "if" statement within your Update() function.

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 ryf9059 · Jun 17, 2013 at 03:36 PM 0
Share

I mean to stop it at runtime. If I know there is a dead loop before I run I will surely get rid of it.

avatar image bubzy · Jun 17, 2013 at 05:03 PM 0
Share

nopey :(

avatar image
0

Answer by GilesDMiddleton · Oct 05, 2015 at 05:52 PM

Infinite loops can easily happen in untested or complex loops.

Typically you have to kill the process to get out of them. This isn't so much of a problem unless you have unsaved changes. You can, however save your unsaved changes by calling methods on the EditorApplication to save the scene. See this post http://answers.unity3d.com/answers/1076468/view.html I wrote yesterday.

One way to protect yourself against infinite loops, and occasional stupidity, could be to use a static bool variable, lets call it

 static bool bPanicButton=false;
   while( true && !bPanicButton )
     {
      <do things>
     }

Debug-break the loop by setting a breakpoint in the debugger and then change bPanicButton to true in the debugger- you can change the value of variables in the Locals/watch window.

I have also used

 Destroy(this); 

To get out of some situations, but rarely works.

Comment
Add comment · 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
0

Answer by meat5000 · Oct 05, 2015 at 05:26 PM

On a similar thread, the suggestion was to open Mono and attach the debugger. You can then use Mono to Pause the running game in Unity. Win!

Comment
Add comment · 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

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

19 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

Related Questions

How to get rid of the crash error in MonoDevelop 2 Answers

Unity iPhone is crashing whilst running my game - how to debug? 2 Answers

How can I find editor log file? 5 Answers

Setup parameters and play scene from editor script 1 Answer

Object limit in Editor (crash) 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