Draw 3D Debug Points, Lines, and Spheres: Visualize Your Algorithm in Action

From Epic Wiki

Overview

Dear Community,

UE4 comes with awesome 3D Drawing features for drawing anywhere in the world!

I consider these tools essential for debugging any algorithm or custom game feature that you are creating.

Draw Debug tools are how you can easily visualize what your code is doing.

Draw Debug helps you see the transition from 2d words to 3D shapes and movement through 3D space

First of all, we need to include "DrawDebugHelpers.h" to use these utilities.

Enjoy!

Draw Point

Definition

ENGINE_API void DrawDebugPoint(
	const UWorld* InWorld, 
	FVector const& Position, 
	float Size, 
	FColor const& PointColor, 
	bool bPersistentLines = false, 
	float LifeTime=-1.f, 
	uint8 DepthPriority = 0
);

Code Sample

DrawDebugPoint(
	GetWorld(), 
	Location,
	20,  					//size
	FColor(255,0,255),  //pink
	false,  				//persistent (never goes away)
	0.03 					//point leaves a trail on moving object
);

Draw Line

You can choose how thick the line should be, Thank You Epic!

Definition

ENGINE_API void DrawDebugLine(
	const UWorld* InWorld, 
	FVector const& LineStart, 
	FVector const& LineEnd, 
	FColor const& Color, 
	bool bPersistentLines = false, 
	float LifeTime=-1.f, 
	uint8 DepthPriority = 0, 
	float Thickness = 0.f
);

Code Sample

//in a non-Static class
//Draw the Line!
DrawDebugLine(
	GetWorld(), 
	LinkStart, 
	LinkEnd, 
	FColor(255,0,0), 
	false, -1, 0, 
	12.333
);

Draw 3D Sphere

You can choose how detailed the sphere is!

Definition

ENGINE_API void DrawDebugSphere(
	const UWorld* InWorld, 
	FVector const& Center, 
	float Radius, 
	int32 Segments, 
	FColor const& Color, 
	bool bPersistentLines = false, 
	float LifeTime=-1.f, 
	uint8 DepthPriority = 0
);

Code Sample

//in a non-Static class

//Start Point
DrawDebugSphere(
	GetWorld(),
	SphereCenter, 
	24, 
	32, 
	FColor(255,0,0)
);

LifeTime

You can set the lifetime in seconds,

 float LifeTime=-1.f,

but if you are drawing every tick make sure you do NOT do this,

or you are creating way more lines than you need to be :)

bPersistentLines

 bool bPersistentLines = false

if you set this parameter to true , debug object stay in world permanently until you call somewhere:

 FlushPersistentDebugLines(GetWorld());

Using this combination you can achieve that lines persist even when simulation is paused and your draw-debug-lines functions in Tick() stops to calling, so you can quietly study your lines.

Video

In this video, toward the middle ( 3:05 ), I show my in-game 3D Kismet system,

and I am using draw debug sphere and draw debug line for the links between the 3D objects :)

<youtube> https://www.youtube.com/watch?v=IJXcuOA8POo

All Draw Debug Functions

See DrawDebugHelpers.h for all the available 3D Debug drawing helpers!

Summary

Enjoy these Draw tools, some of my favorite functions!

( )