Home > Back-end >  Make the Visual Studio debugger break on Unity's AssertionException?
Make the Visual Studio debugger break on Unity's AssertionException?

Time:09-30

I'm probably missing something trivial here, but I can't seem to get Visual Studio to break on AssertionException's raised by Unity assertions.

I can break on other exceptions (invalid arguments etc.), so I know Visual Studio is set up correctly, and I can see the exception being raised in the log (so I know assertions are set up correctly), it's just not breaking in the debugger.

I tried adding custom exceptions to Visual Studio's Exceptions panel (e.g. UnityEngine.Assertions) but that didn't change anything.

I'm thinking that's the answer but I'm just not adding these custom exceptions in the right spot or with the right syntax?

Note: if I break on ALL exceptions that will probably work but I don't want to because that causes Visual Studio to break on a ton of otherwise-benign exceptions in third-party modules/libraries. I would like to know what is the unity assertion exception and catch that one.

CodePudding user response:

since 2019.2 what you want should actually be the default behavior:

Assert throws exceptions by default whenever an assertion fails. You can however set Assertions.Assert._raiseExceptions to false and Unity then logs a message using LogType.Assert instead.

and that flag is actually going to be removed entirely.


In 2019.1 and before it was the other way round

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.

and you need to actively set

Assert.raiseException = true;

CodePudding user response:

I had similar issue before and it was related to whether process is running in 32 or 64 bits mode. I had to run it in 32 bits mode to make it break

  • Related