Debug Draw Line3D

Godot Version

4.2.2 ( c# )

Question

I would like to know if there is an option to debug draw a line in a 3D environment.

Not built-in, but it’s pretty simple:

extends MeshInstance3D

@export var m_pntStart : Vector3 = Vector3.ZERO : get=getStart,set=setStart

@export var m_pntEnd : Vector3 = Vector3.ZERO : get=getEnd,set=setEnd

var m_color : Color = Color.GREEN

var m_material : ORMMaterial3D = ORMMaterial3D.new()

func _ready():
	mesh = ImmediateMesh.new()
	m_material.shading_mode = BaseMaterial3D.SHADING_MODE_UNSHADED
	
func _process(delta):
	draw()

func getStart():
	return m_pntStart

func getEnd():
	return m_pntEnd
	
func setStart(a : Vector3):
	m_pntStart = a
	
func setEnd(a : Vector3):
	m_pntEnd = a

func setColor(a):
	m_color = a
	m_material.albedo_color = m_color

func draw():
	mesh.clear_surfaces()
	mesh.surface_begin(Mesh.PRIMITIVE_LINES, m_material)
	mesh.surface_add_vertex(m_pntStart)
	mesh.surface_add_vertex(m_pntEnd)
	mesh.surface_end()

Yeah, there is no real built-in option.
Except when you are making a GizmoPlugin for some reason.

If you are planning on extensively using debug shapes, there is this great addon for that. It is made with GDExtension so its very good performance wise.

But if you don’t like to install addons, you can always make your own custom draw function like the above code.
I have made a video tutorial making a simple line renderer if you prefer that.