4
\$\begingroup\$

I'm writing a 2D game with some fairly complex off-screen logic, with plenty of room for bugs. My usual habit is to write code with a lot of Asserts in it. When an Assert gets hit I drop into the debugger, have a look around, find and fix the bug. Works for me.

Problem is: how to get Unity Asserts to call into the Visual Studio debugger. So far they just seem to get generate a log message in the Editor Console, and then Unity carries right on as if they didn't matter. What use is that?

There is an 'experimental' option in the Unity VS settings, but it doesn't seem to do anything (good or bad). Any suggestions? I can think of a couple of really hackish things to try, but surely there must be a right way?


After further experimentation:

  1. Enabling Assert.raiseExceptions (only) makes Unity grind to a halt (instead of carrying on regardless) but otherwise no change. No trap into VS.
  2. Enabling the experimental Exceptions mode (only) causes Unity to crash with a bug check on the first assert failure.
  3. Doing 1+2 is the same as 1 only.

This is VS 2015 in case it matters.

\$\endgroup\$
0
\$\begingroup\$

Do you have Assert.raiseExceptions set? If not it won't stop the execution according to the docs. Relevant info copied here:

A failure of an assertion method does not break the control flow of the execution. On a failure, an assertion message is logged (LogType.Assert) and the execution continues. If Assert.raiseExceptions is set to true, an AssertionException is thrown instead of logging a message.

\$\endgroup\$
  • \$\begingroup\$ Sorry, I did RTFM and that is not the answer. See edit. No useful effect. \$\endgroup\$ – david.pfx Nov 11 '16 at 7:40
  • \$\begingroup\$ I saw somewhere that if it was the Unity VS installed with Unity itself, it wasn't working but if you reinstall it manually it may work. I don't think you're the only one with problems though \$\endgroup\$ – Coburn Nov 11 '16 at 8:09
  • \$\begingroup\$ thanks, I think you're right. Perhaps in the fullness of time... \$\endgroup\$ – david.pfx Nov 15 '16 at 23:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.