Search Unity

  1. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice
  2. Unity is excited to announce that we will be collaborating with TheXPlace for a summer game jam from June 13 - June 19. Learn more.
    Dismiss Notice
  3. Dismiss Notice

Question Anyone know why the VS Debugger breakpoints just randomly stop working ??

Discussion in 'Code Editors & IDEs' started by cuzner, Jun 7, 2020.

  1. cuzner

    cuzner

    Joined:
    Oct 1, 2015
    Posts:
    11
    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.

    Anyone have anymore ideas on how to solve this?
     
    olegrolik likes this.
  2. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    39,356
    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.
     
  3. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    39,356
    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.
     
  4. Chief_Ed

    Chief_Ed

    Joined:
    Jul 7, 2013
    Posts:
    4
    This problem is alive and well with Unity 2021.1.4 and the latest version of VSCode. I also, am ready to pull my hair out (if I had any left!).

    Is there anywhere that explains - step-by-step, how to set up Unity to run with VSCode?

    I MUST be doing something wrong! The code seems to run fine, but it just ignores breakpoints.
    -Thank you!
     
  5. tabulatouch

    tabulatouch

    Joined:
    Mar 12, 2015
    Posts:
    26
    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....
     
  6. DrunkenMastah

    DrunkenMastah

    Joined:
    Sep 26, 2017
    Posts:
    51
    This worked for me.
    I created a batch file to run this every time I get stuck. Thanks!