Search Unity

Towards resolving breakpoint and code diving issues for your own external code

Discussion in 'Code Editors & IDEs' started by sdtr443w, Apr 4, 2021.

  1. sdtr443w

    sdtr443w

    Joined:
    Nov 29, 2014
    Posts:
    23
    I have some external projects I include in Unity in a References folder. The code generally works, but I sometimes have to debug it with context from Unity. Every few months, the planets realign and this stops working. There are two problems that I think a lot of people have seen:

    1. You just get the metadata when trying to go to the definition of the external code.
    2. When in the external project attached to Unity, none of the breakpoints hit. Instead, you see "The breakpoint will not currently be hit. Unable to find corresponding location" It stays this way even after entering play mode.

    Before we continue, I managed to fix #2 for myself and I'm posting that here, but I'm trying to figure out #1 as well.

    When I build these external libraries, I have build events copying all the .dll and .pdb files automatically to my project's References path.

    For my work, I'm currently using:
    Visual Studio 2019 16.9.3
    Visual Studio Tools for Unity 4.9.1.0 (latest at time of notes)
    Unity 2019.3.7f1

    I've seen a huge pile of suggestions towards #2 and just started to rigorously go through a pile of them. What ultimately worked were two things together:

    1. Deleting old .mdb files in my References path. I think they were vestigial from awhile ago when you had to use .mdb files instead of being able to use .pdb files. One of my projects started to trigger as soon as I did that.
    2. Setting the Debugging Information format from "Full" to "Portable." I had multiple external projects set between these settings and the ones still set to "Full" could not hit breakpoints. Then the rest of them could break in the debugger.

    Things that did not made a difference:
    1. Multiple levels of Unity and computer restarts. It doesn't care.
    2. Reimporting the asset database.
    3. Changing the encoding of these source files. They were UTF8-BOM but so were the files inside my actual Unity project. I tried anyways and it made no difference, so I switched back to UTF8-BOM.
    4. Trying to slap a System.Diagnostics.Debugger.IsAttached call into the external code and breaking inside the block.

    Things I didn't try:
    1. Something I've dubbed "The Korean Method" since it was written in Korean in a thread. Basically create a new project and beat Unity over the head with it. I suspect it helps if Unity cannot even attach to its own projects.
    2. Deleting all references and just starting over. I'm basically doing that whenever I rebuild and overwrite that folder with my outputs.

    The fact that I had to do two separate things implies this is a fussy problem that can happen multiple ways. So I may dismiss these other methods but they probably worked for somebody else in their particular situation.

    So at this point, I can open these projects in a separate VS2019 instance, attach, and step through them. However, I cannot step into them despite having all the symbols. I remember doing that once a long time ago, and I also recall it screwing up too according to the orientation of the planets or whatever.

    One of my projects is a scripting interpreter and I have a lot of scripts going through it. I'd prefer to be able to hit a breakpoint from inside the Unity project that would walk me into a specific invocation rather than sitting in the external project, trying to step past all the calls I want to ignore. I know I can work around it, and I do, but I also know that it has let me step into it in the past. I haven't figured out how to fix it yet.

    Last time it magically started working again, I had switched to VS2019. So I basically had a fresh, new IDE install. I'm now in VS2019 again, although with some more time and updates, and it has once against stopped working.
     
  2. sdtr443w

    sdtr443w

    Joined:
    Nov 29, 2014
    Posts:
    23
    Stepping into the code from the Unity project was a silly thing. At some point, I had enabled "Just My Code" in the Tools->Options->Debugging->General category. After unselecting that, I could step into the external code just fine.

    Well, I had to restart VS2019 and Unity that time to get it to stick.