Debug.Break() ; not working properly

I have this code

Debug.Break() ;
print("Break was ignored")

When I run the script " I see Break was ignored" in the console. I am trying to test my variables and I am unable to test them since I get the results back that was posted after the debug break. I have another line after print and the whole script gets called, so I am unable to check my variables before the break was issued.

Debug.Break() ;
print("Break was ignored");
EditGridColor(thePath);

Do I under stand Break wrong? I am trying to pause the app so I can see the where I am currently at and why my results are not how they should be.

also if I have 2 Breaks, the app will only break one, so I can’t break, continue, break, continue. I will only do break continue, does not matter how many breaks you have, even if you have like 10 breaks.

Debug.Break() ;
print("Break was ignored");
EditGridColor(thePath);
Debug.Break() ;
print("This Break was totally ignored");

P.S. After Debug.Break(), all the scripts ran and then game paused.

Debug.Break just pauses the editor when the current frame is finished. It’s just like you clicked on the pause button manually but you can trigger it at a specific frame. If you want to do code analysis you have to use the debugger like robertbu said. There you can set break points on every line you want.

edit
Unfortunately the unitygems site seems to be hacked / offline for some weeks now. Here’s Unity’s documentation on the debugger.

I know this is an older thread but I thought I could weigh in, in case someone else comes across this and it might help. If you want to pause the editor and stop the rest of the code from running then after
Debug.Break();
just add
return;
This will stop the rest of the code running in that script, it’ll become obvious because in visual studio the code underneath “return;” will become dim. It won’t, however, stop the rest of the code in other scripts from running at the moment return is called, every other script will still finish its update frame.

Here is a solution that gets basically what you want:

  1. Copy the System.Windows.Forms.dll file into your Assets folder somewhere. (you can find it here: C:\Program Files\Unity\Editor\Data\Mono\lib\mono\2.0)

  2. Add these lines in place of the “Debug.Break();” line:

     MessageBox.Show("Something happened. Attach the debugger, add a breakpoint to the line after this one, then press OK.");
     "does nothing".ToString(); // place breakpoint here
    

Now when that area of code is hit, the message-box will show, and will block the code execution. Then just add the breakpoint to the line after (as it says), press OK, and the code will resume and hit the breakpoint you just added.

It’s a bit more work than just a BreakHere(); call, but it accomplishes the same thing.

Edit

For those who don’t want to add a DLL to their project, you can also just call the User32.dll’s MessageBox method directly.

Here’s a paste-bin showing the working code for this variant: CustomDebug - Pastebin.com

In this case, you’d call “Assert(false);” from the line where you want to break. (then just use the “Call stack” window to go up one method and inspect the state)

Even i figured out u have to do System.Windows.Forms.MessageBox, still window shows but as i click okay nothing is happening the game keeps on going afterwards