- Home /
Really Simple: Debug.DrawLine just will not show up
This should be really easy to solve. I must be high on something, because I cannot figure it out.
function Update () {
Debug.DrawLine(Vector3(200,200,200), Vector3.zero);
print("You should see a line");
}
This code will print the text, but it will not draw any lines. Why not? I've got to be missing something simple.
Answer by hirenkacha · Sep 12, 2012 at 05:15 AM
it is because it will draw a line for a single frame. if you want to see a line for longer use this. `Debug.DrawLine(Vector3(200,200,200), Vector3.zero, Color.green, 2, false);`
where `DrawLine (start : Vector3, end : Vector3, color : Color = Color.white, duration : float = 0.0f, depthTest : boolean = true)` .
Thank you for your answer, but it's something else that is causing this problem, it seems.
I already knew about the duration variable, but I copy and pasted your code to try it just in case. I even changed the duration to 20. Still no line.
I only have a simple plane and a first person controller in my scene, both near (0,0,0). But there is no line.
(If I put the DrawLine command in an Update() function, won't it redraw every frame? If so, I don't understand why I would need a duration value)
DrawLines are only visible in scene view not in game view. i hope you are aware of it.
i found this working on my pc for c#.
Debug.DrawLine(new Vector3(200f,200f,200f), Vector3.zero, Color.green, 2f, false);
Ohhh okay. I had my Unity windows set to full screen, so that hitting "play" would switch over to full screen GameView, and I would never see the lines being rendered in SceneView. I didn't know they wouldn't render in Gameview.
Thank you. That makes sense now, but now it seems I am forced to create a LineRenderer object in order to draw a simple debug line. That seems silly to me, but alright, if that's what I must do.
Thank you again.
Lines do render in gameview, but they count as gizmos, so you have to have Gizmos enabled. It's the button in the top right corner of the game view.
Answer by DefaultPain · Aug 06, 2016 at 07:50 PM
when u click on the play button to play the scene,u have to enable gizmos,which are on the top right corner.then u will see the lines.case closed.
I can only see the other gizmos like light, but no line, line only appears on scene view, why...
Each view has its own gizmos option, so you should also activate gizmos in your game view.
Answer by hamy6342 · Sep 28, 2017 at 07:02 PM
@CHPedersen Have Gizmos button enabled but still line won't show up even in scene view.
Answer by Lokiare · Oct 30, 2014 at 05:55 PM
Because time is independent of frame rate you have to tell it to draw the line for the time between frames:
Debug.DrawLine(Vector3(200,200,200), Vector3.zero, Color.green, Time.deltaTime, false);
If you use something other than "Time.deltaTime" then you either won't see the line or it will create tracers (multiple lines) and you can only see the lines in the editor view so make sure you take your game out of full screen when testing it.
Answer by Aeroxima · Aug 08, 2018 at 08:15 PM
I know this is old (comes up in google), but I got away with a cube scaled to (0.01, 0.01, 10) for my purposes. I made it 50% transparent and turned off shadows (cast and received, in its mesh renderer).
Your answer
Follow this Question
Related Questions
Raycast and Debug Line Position 1 Answer
Converting Debug.drawlines to in-game lines? [screenshot inside] 3 Answers
Not getting where error comes from which line when debugging on Android 1 Answer
Calculate needed resolution to draw curve from line segments in editor 1 Answer
Debug.DrawLine problem 1 Answer