I have no problem breaking VS on placed break points when debugging but if unity code throws an exception then Unity can be made to pause the game and show where the error occurred in the console…
but I want it to switch to VS and show the current call stack, variable values etc. - should I be able to?
As it is, I have to repeat the actions with a new breakpoint at the point of exception to get a proper look at the error in VS, seems a Unity limitation
Sorry to necro this, but is the mentioned setting above really the solution?
Would also like that when the NullReferenceException occurs (unintialized variable etc.), the debugger should stop to show me which variable is the culprit (since the error log does only provide the line and sometimes have multiple reference sin the same line).
However despite this (which already was enabled) no exceptions are thrown.
There’s a separate, Unity-specific exception called “MissingReferenceException” which is thrown in the Editor when a reference to a Unity object is a “fake null”.
Also, sometimes I have to toggle the exception off then on again after attaching the debugger for it to stick.
For folks wondering how to add the MissingReferenceException in VS:
Right click “Common Language Runtime Exceptions” in the screenshot above, hit the plus-icon and add “UnityEngine.MissingReferenceException”
And yes, I’ve also seen a lot of flakyness with getting this to work reliably like needing to toggle exceptions on and off to get it to work (never had a problem with any other targets than Unity).
How is this not the default? I’ve spent YEARS just dealing with Unity pausing and VS not breaking. I didn’t even think to search for if it was even possible for VS to break when Unity encounters an exception until today.
Pro-tip: In the Exception Settings window, just make sure Common Language Runtime Exceptions is checked, and VS will break on every Unity exception thrown.
Why you wouldn’t want VS to break on an exception is beyond my logical reasoning.
[Edit] Now I’m getting exceptions in code I don’t even know existed. Might be best to just manually add UnityEngine.[ExceptionName] for each exception you want to catch.
[Edit2]
Click the ‘Restore the list to the default settings’ button
Check ‘All Common Language Runtime Exceptions not in this list’ under ‘Common Language Runtime Exceptions’
Profit!
Adding “UnityEngine.MissingReferenceException” worked for me, but checking ‘All Common Language Runtime Exceptions not in this list’ did not work for me. Where is a complete list of all these UnityEngine exceptions? Am I supposed to be able to figure this out on my own, or is this just a critical feature still missing?
I’ve come back to this as it is not breaking for me on NullReferenceException with UnityEngine.MissingReferenceException added (Unity 6.1, latest VS).
Sure makes debugging harder…!
This is on a plain C# class too, but default exceptions are unchanged