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
3
Question by sarahnorthway · Mar 07, 2016 at 12:29 AM · editorvisual studiodebugging

How to pause the Unity editor while at a debug breakpoint

I've connected the Visual Studio, set a breakpoint and successfully stopped at that point. Now I want to pause Unity and take a look at the current state of the scene from inside the Unity editor. But debugging in VS seems to lock the Unity editor up completely and I can't even switch to it let alone CTRL+SHIFT+P. If I hit Continue first, the scene will change and it will be too late.

Is there some way to pause the Unity editor from C# code? Any other suggestions?

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

2 Replies

· Add your reply
  • Sort: 
avatar image
2

Answer by sarahnorthway · Mar 07, 2016 at 12:41 AM

I think Debug.Break() is how you're supposed to pause the Unity editor from within code, but it seems to wait until the end of the frame to pause.

Eg if I do: Debug.Log("hi"); Debug.Break(); Debug.Log("bye");, the editor will pause but I see "bye" in the console (and a lot of other stuff which destroys the state I'm trying to analyze). This might be as good as it gets?

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 Wappenull · Jul 11, 2020 at 07:32 AM 0
Share

Note to future reader. Debug.Break will only signal Unity editor to pause after current frame update has completed. That's mean all script has run for 1 completed cycle. So your "bye" will still print.

To prevent code to continue you could insert throw exception after Debug.Break(). Such as "throw new Exception( )"

Code will spring out as if there is error on throw line.

avatar image
1

Answer by Wappenull · Jul 11, 2020 at 07:26 AM

More tip I discovered for Debug.Break();

If you want to pause an editor from debugger, the frame you are debugging right there right now.


Practical Example:

For instance, while in debugger, if you want to see object in scene after Instantiate was called, but the play mode is still running, it would be too late to hit F5 (debugger continue), switch back to editor, pause the run, and see the object. As many frames would have elapsed.


Solution:

= Add new watch expression and paste UnityEngine.Debug.Break() into a line. This will execute a code like it is running from your script. Which will sent to editor.

= Note that Value is displaying "Unable to evaluate" because it is function with no return value so nothing for watch window to show, this is normal. alt text


= Continue your code as usual (F5). Now switch back to editor and notice that editor is paused.

= That watch line will not repeatly executed because expression is function. If you want it to run again, you could click at reevaluation button (round circle arrow)


break.png (15.8 kB)
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

55 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

Related Questions

Updating Visual Studio Editor broke all my code. 0 Answers

Microsoft (R) Visual Error With # Compiler version 3.5.0-dev-20359-01 (8da8ba0c) Copyright (C) Microsoft Corporation. All rights reserved. 0 Answers

Why is VS15 throwing errors for missing namespace 'UnityEngine' when it is already included 0 Answers

Visual Studio Debugging, sometimes can't see value of some local variables 0 Answers

Custom Editor and Visual Studio 'Solutions' 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