Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

How to print object's data into Unity debugger console?

Discussion in 'Scripting' started by FellowPlayer123, Jul 12, 2018.

  1. FellowPlayer123

    FellowPlayer123

    Joined:
    Dec 23, 2016
    Posts:
    114
    I would like to click (just like in web browsers) in a console on the object and see what's inside it.
    But in Unity, I can not view anything when I click on it. How to view what's inside it?
     

    Attached Files:

    • 1.png
      1.png
      File size:
      5.4 KB
      Views:
      1,580
  2. LiterallyJeff

    LiterallyJeff

    Joined:
    Jan 21, 2015
    Posts:
    2,802
    That's what the inspector is for when you click an object in the hierarchy. You can expose an object's data in the inspector by making public fields or use the Debug view to see any serializable private fields as well.

    Screen Shot 2018-07-12 at 2.35.30 PM.png
     
    flyingpixel likes this.
  3. FellowPlayer123

    FellowPlayer123

    Joined:
    Dec 23, 2016
    Posts:
    114
    I know I can see data in the inspector when I make variables public or [SerializeField]. I also have debug mode activated.
    You didn't understand me. I would like to see all properties inside Debugger just as it is in web browsers consoles.
     
  4. BlackPete

    BlackPete

    Joined:
    Nov 16, 2016
    Posts:
    970
    If you click on the line in the console, it should select that object in the hierarchy and therefore also show it in the inspector, which is where you can use Debug mode to view its properties.
     
  5. FellowPlayer123

    FellowPlayer123

    Joined:
    Dec 23, 2016
    Posts:
    114
    No.
    What you're saying is just false.
    Nothing happens.
    When I click on the line in the console nothing happens.
    When I double click it, code editor with my script is opening.
     
    elgindavis likes this.
  6. FellowPlayer123

    FellowPlayer123

    Joined:
    Dec 23, 2016
    Posts:
    114
    Here's how it works in web browser (firefox in my case).

    I have declared an array variable called test with string items inside it. When I output test into the console I can easily see and access all the elements.

    In Unity debugger, when I print the same variable into the console, I only see that it is an object.

    Can't see what's inside it.

    Can't extract data from it.
     

    Attached Files:

    • 3.png
      3.png
      File size:
      6 KB
      Views:
      1,767
  7. AndersMalmgren

    AndersMalmgren

    Joined:
    Aug 31, 2014
    Posts:
    5,358
    You need to break at a line in visual studio than use the watch
     
  8. WheresMommy

    WheresMommy

    Joined:
    Oct 4, 2012
    Posts:
    890
    Well, the debugger is just a string parser, it won't show you something besides the thing you throw at it exactly. You should write some class yourself that handles that for you or look for some asset in the store, that might do that.
     
  9. karl_jones

    karl_jones

    Unity Technologies

    Joined:
    May 5, 2015
    Posts:
    7,846
    Try this:
    Code (CSharp):
    1.     public static void DumpToConsole(object obj)
    2.     {
    3.         var output = JsonUtility.ToJson(obj, true);
    4.         Debug.Log(output);
    5.     }
    Just pass in the object you want to see the data from. It will show all serializable fields(like the inspector)
     
  10. FellowPlayer123

    FellowPlayer123

    Joined:
    Dec 23, 2016
    Posts:
    114
    Thank you for this simple and wise answer.

     
    KUBODeveloper and karl_jones like this.
  11. FellowPlayer123

    FellowPlayer123

    Joined:
    Dec 23, 2016
    Posts:
    114
    For some objects, it doesn't work. The console prints error when I pass some objects into this methods.

    Screenshot included.
     

    Attached Files:

    • 5.png
      5.png
      File size:
      4.6 KB
      Views:
      1,376
  12. karl_jones

    karl_jones

    Unity Technologies

    Joined:
    May 5, 2015
    Posts:
    7,846
  13. AndersMalmgren

    AndersMalmgren

    Joined:
    Aug 31, 2014
    Posts:
    5,358
    You can probably use Newtonsoft to seriallize engine types, but like I said, put a breakpoint and watch the variable
     
  14. yaach

    yaach

    Joined:
    Aug 9, 2019
    Posts:
    5
    This worked for me!
     
    karl_jones likes this.
  15. xaldin-76

    xaldin-76

    Joined:
    Oct 1, 2016
    Posts:
    24