Search Unity

Inline debug statements

Discussion in 'Editor & General Support' started by nsmith1024, Dec 5, 2019.

  1. nsmith1024

    nsmith1024

    Joined:
    Mar 18, 2014
    Posts:
    870
    Hello,

    I have a large Unity project and i want to be able to enable or disable debug statements and also find out which line those debug statements were printed at.

    For example

    1.public class test1 {
    2. x=10
    3. MyDebug("this is a debug statement"); // <<<
    4. y=5;
    5. }

    1.public class test2 {
    2. x=10
    3. y=5;
    4. MyDebug("this is a debug statement"); // <<<<
    5. }

    1. class debug {
    2. public static void MyDebug(string msg)
    3. {
    4. if (true) {
    5. Debug.Log("msg");
    6. }
    7. }
    8. }

    When you run this code, it will print 2 debug lines in the unity console, one from class test1 and the other from class test 2.

    The problem is that in the unity console when you click on either of those debug output statements, the unity debugger will open Visual Studio and take you to the debug class line 5 because that's where the actual debug print statement is located.

    But i want it to actually take you to the original lines which are class test1 line3, and class test2 line 4.

    To do that i want seems i need to INLINE the debug MyDebug function so that when you click on the debug statement in the unity console, it will take you to the test 1 class line 3, or the test 2 class line 4.

    I have thousands of this type of thing in my project, and its a real pain because when i click on the debug message in the unity console, it takes it to the same line in the debug class even though that is not the correct place, i have to look at the stack and then figure out who called that line and then manually open that file and manually go to that line, it just takes a lot of time to do all that.

    Is it possible to get taken to the correct file and line when i click on the debug message in the console?
     
  2. Olmi

    Olmi

    Joined:
    Nov 29, 2012
    Posts:
    1,553
    Hi,

    Could you please edit your post to use code tags. You can find them in message editor next to where it says "Code:".