Search Unity

Debug.Drawline() not visible in Scene or Game window

Discussion in 'Scripting' started by Maulkye, Jun 18, 2010.

  1. Maulkye

    Maulkye

    Joined:
    Jun 18, 2010
    Posts:
    11
    Is there some basic setting I need to enable such that the Debug.Drawlines will be visible?

    My build is not a Deployment build and I've tried with and without Gizmo's on. The lines do not show up either the Game or Scene view. Here's what I've most recently tried:

    Code (csharp):
    1.  
    2. print("Draw Line");
    3. Vector3 p1 = Sphere1.transform.TransformPoint(Sphere1.transform.position);
    4.  
    5. Vector3 p2 = Sphere2.transform.TransformPoint(Sphere1.transform.position);
    6.  
    7. Debug.DrawLine(Sphere1.transform.position, Sphere2.transform.position, Color.yellow);
    8.  
    9. Debug.DrawLine(p1, p2, Color.cyan);
    10.  
    I created a new scene, added a basic terrain, skybox, and ambient lighting. I dropped two spheres in the world (they are not attached under any parent object though I tried that too) and I've attached them to the script above which itself is a component on the sole Main Camera in the scene (part of the FP Prefab).

    I can get their positions and even move them about by reference, but I can't get the debug lines to show up to save my life.

    Unity 2.6 free version.

    Many thanks for any help!
     
  2. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    Debug.DrawLine is editor-only and doesn't show up in builds. A line lasts for one frame, so unless you pause the editor when drawing a line or draw it every frame, you won't see it.

    --Eric
     
  3. tylo

    tylo

    Joined:
    Dec 7, 2009
    Posts:
    154
    I've noticed that p1 and p2 seem to be the same location, but that doesn't explain why your yellow line wouldn't appear.

    Like he said, you do need to have the Debug.DrawLine in an Update method to display continuously.
     
  4. Maulkye

    Maulkye

    Joined:
    Jun 18, 2010
    Posts:
    11
    Arg, that's a typo in my post. I checked my code and the points are different there. I edited the original post. Thanks for the spot.

    OK, I'm drawing the line when the user presses a key, so I guess it must be disappearing the very next frame. I'll give it a test this evening.

    Thank you very much for your responses! :D

    PS - I'm not actually trying this in a build. My choice of wording there was poor. I just meant that I was working in the editor with all debugger settings showing as enabled.