Search Unity

Debug Output

Discussion in 'Scripting' started by marty, Jun 1, 2005.

  1. marty

    marty

    Joined:
    Apr 27, 2005
    Posts:
    1,170
    If I want to watch certain values in realtime while I debug my code while I am debuggin it (i.e. with the JavaScript 'trace' command), where can I send them?
     
  2. Joachim_Ante

    Joachim_Ante

    Unity Technologies

    Joined:
    Mar 16, 2005
    Posts:
    5,203
    There are three good ways to debug values in unity depending on the situation.

    1) Create a variable in the script and change it every frame to the value you want to debug. The inspector will then update every frame in playmode and show you the changed value.
    Eg. Attach the script below to any object. debugValue will appear in the inspector. If you enter playmode, it will update every frame and be the time since you hit play.
    Code (csharp):
    1.  
    2. var debugValue =5.0;
    3. function Update () {
    4.   debugValue = Time.time;
    5. }
    6.  

    2) Debug.Log prints to the unity console. It also includes a stacktrace.

    3) Debug.DrawLine is useful for visualizing 3D math. It draws a line in the scene view.
     
  3. Boss

    Boss

    Joined:
    Jun 27, 2012
    Posts:
    133
    Very nice script. 2005 thread to the top. :)