Reputation: 677
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.
Upvotes: 2
Views: 1484
Reputation: 677
OK so turns out I was right to expect this behavior to be possible! I am not sure if this should have been configured by Unity by default and my settings got corrupted somehow, but either way:
If you want Visual Studio to BREAK (through an exception) on a Unity assertion (e.g. Assert.Istrue(...)
), you must add the following exception to your "Common Language Runtime Exceptions" setting (Debug-> Exception Settings):
UnityEngine.Assertions.AssertionException
Upvotes: 2
Reputation: 1418
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
Upvotes: 0
Reputation: 90570
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
Upvotes: 0