Search Unity

  1. The Unity Pro & Visual Studio Professional Bundle gives you the tools you need to develop faster & collaborate more efficiently. Learn more.
    Dismiss Notice
  2. Improved Prefab workflow (includes Nested Prefabs!), 2D isometric Tilemap and more! Get the 2018.3 Beta now.
    Dismiss Notice
  3. Want more efficiency in your development work? Sign up to receive weekly tech and creative know-how from Unity experts.
    Dismiss Notice
  4. Participate with students all over the world and build projects to teach people. Join now!
    Dismiss Notice
  5. Build games and experiences that can load instantly and without install. Explore the Project Tiny Preview today!
    Dismiss Notice
  6. Improve your Unity skills with a certified instructor in a private, interactive classroom. Watch the overview now.
    Dismiss Notice
  7. Want to see the most recent patch releases? Take a peek at the patch release page.
    Dismiss Notice

Debug with Unity released source code

Discussion in 'Editor & General Support' started by hicksplace, Jul 7, 2018.

  1. hicksplace

    hicksplace

    Joined:
    Sep 10, 2017
    Posts:
    4
    I am trying to debug into the Unity Editor with the recent released unity source code and VS2017.
    As an experiment, I am trying to set a breakpoints in the Help->About Unity code.

    The breakpoint always displays this friendly message:
    "The breakpoint will not currently be hit. Unable to find a corresponding location"​

    Installed:
    Unity 2018.1.6f1
    Downloaded branch 2018.1 from GitHub.
    https://github.com/Unity-Technologies/UnityCsReference

    Things I’ve tried:

    1. Open source code solution and attached to Unity debugger:
    In VS2017
    open projects/CSharp/UnityReferenceSource.sln
    ‘Attach Unity Debugger’
    Set breakpoint in UnityEditor->Editor->Mono->GUI->AboutWindows.cs​
    In Unity
    open Help->About Unity​
    Nothing happens​

    2: Compile and replace UnityEditor.dll
    In VS2017
    UnityEditor properties
    Change TargetFramework to: Unity 3.5 .net full Base Class Libraries
    Compile UnityEditor
    Copy compiled UnityEditor.dll to Unity directory in c:\Program Files​
    Run Unity
    Unity crashes​

    3: Make UnityEditor.dll debuggable
    Tried some techniques from this article:
    https://astrangergravity.com/writing/2018/debugging-into-unitys-internals

    convert the UnityEditor.dll to UnityEditor.il
    convert back to UnityEditor.dll with /debug enabled.
    C:\> ildasm UnityEditor.dll /out=UnityEditor.il
    C:\> ilasm /dll /debug /Out:UnityEditor.dll UnityEditor.il

    There already exists a UnityEditor.dll.mdb file so I tried with that. Didn't work

    Took the UnityEditor.pdb from the compiled source code and converted it to UnityEditor.dll.mdb and coped into Unity directory. Again, debugging doesn't work.
    Much appreciate any help
     
  2. DreamPower

    DreamPower

    Joined:
    Apr 2, 2017
    Posts:
    42
    I thought the source code was only for the C# bits, that they didn't include any of the native C++ code. Because Unity doesn't want anybody compiling it for any reason, they make a big point about "this is only for reference"
     
  3. hicksplace

    hicksplace

    Joined:
    Sep 10, 2017
    Posts:
    4
    True, but shouldn't there still be a way to step through the C# bits with a debugger? For me, the best way to 'reference' code is to step through it's execution with a debugger.

    My intent is not to change or recompile the code. That was just a failed experiment to see if I could debug that way.

    I am hopeful this isn't as hard as it seems, and someone else has figured this out.
     
  4. Peter77

    Peter77

    Joined:
    Jun 12, 2013
    Posts:
    2,752
  5. JoshPeterson

    JoshPeterson

    Unity Technologies

    Joined:
    Jul 21, 2014
    Posts:
    3,440
    Peter77 likes this.
  6. hicksplace

    hicksplace

    Joined:
    Sep 10, 2017
    Posts:
    4
    So should I infer that there not a way to link the debugger to the editor?
     
  7. JeffDUnity3D

    JeffDUnity3D

    Unity Technologies

    Joined:
    May 2, 2017
    Posts:
    2,758
    @hicksplace What problem are you trying to diagnose?
     
  8. hicksplace

    hicksplace

    Joined:
    Sep 10, 2017
    Posts:
    4
    None ... at least not yet.

    Just looking to get an understanding of the Unity Editor by following the code execution in the debugger. I find it painful trying to figure out code just reading in linearly.
     
  9. JoshPeterson

    JoshPeterson

    Unity Technologies

    Joined:
    Jul 21, 2014
    Posts:
    3,440
    You can debug script code from your project that is running in the Unity editor. You can't debug the Unity C# code though.