Debugging in Unity is almost impossible for me!!
Anyone know why the VS Debugger breakpoints just randomly stop working ??
No errors, Unity code runs in editor fine.
I add a breakpoint. Save the files.
Select attach to Unity in the Visual Studio. Run the debugger.
Start the Unity file running. …
Nothing happens!
I have followed suggestions to delete the .sln and vs files etc. this works sometimes for a while but then it just stops. I have also setup VSCode to work with Unity - getting same issue.
How am I supposed to debug code when I spend hours fighting the debug tools!!
I have put breakpoints on the initialising function that starts everything and it still does not trigger.
Welcome to Visual Studio! To be fair, even under Monobehavior this was finicky at times, depending on which version of Unity. Here are some possible steps to success, each a separate try:
open and close Unity and visual studio, try reattach debugger
From Unity use Assets → Open C# Project afresh, after deleting the .csproj and .sln files from before. You should not bother source-controlling sln and csproj files, since Unity recreates them on demand. Then try to attach.
create a folder called Plugins if you don’t have one, and create a C# file in there. Let it recompile, then delete it and try to attach debugger.
close Unity and Visual Studio, delete the folder Library/ScriptAssemblies (THE ONE IN YOUR PROJECT!!!), then open Unity. This really triggers a full recompile. Now try to reattach.
Also, NEVER EVER build from Visual Studio. That’s just a complete disaster. Let Unity build it every time.
It is infuriatingly finicky, especially now that Microsoft IDEs are involved, since they go out to about 57,000 system DLLs and each possible DLL ranging from security to drive properties to CPU architectures and all the different versions any computer might have installed all have some kind of weird interactions. It can be annoying af.
Also, at the end of the day, often good instrumentation in your code can reveal almost everything you need. Throw realtime data out to a log, or else up to a UI.Text object onscreen.
The 1980s are alive and well today, with good old Debug.Log(), which of course in the 1980s was called debug_printf();… and the upside to this is that the game remains running, so you can continue interacting with it in realtime, even if log spew makes it slow down and churk a little bit more.
The whole debug experience is wonderful when it works, and a total mess when it randomly stops working…
Happens to me all the time, never found a repeatable pattern to make it work.
If I had a single desire… i would ask for a damn old LOG for Visual Studio Unity tools…