# How to use DrawLines?

**URL:** <https://forums.unrealengine.com/t/how-to-use-drawlines/315549>\
**Category:** C++\
**Tags:** unreal-engine, UE4, CPP, question, linking-error\
**Created:** [April 18, 2015, 7:40pm UTC](https://forums.unrealengine.com/t/how-to-use-drawlines/315549 "2015-04-18T19:40:48Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![LPLedoux](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@LPLedoux](https://forums.unrealengine.com/u/LPLedoux)\
**Post date:** [April 18, 2015, 7:40pm UTC](https://forums.unrealengine.com/t/how-to-use-drawlines/315549/1 "2015-04-18T19:40:48Z")

</div>

Hi !  
Currently, I’m trying to draw a lot of lines at runtime using the function DrawLine. However, it starts to get really non-performant as the number of lines go up (which is normal). I then stumbled upon the function DrawLines, which looks similar but is supposed to be better when drawing a lot of lines. I’ve been trying to replicate a simpler version of the DrawDebugBox function to make sure I’m using it correctly.

Here’s the problem : I get a link error whenever I try to use the function.

Error 1 error LNK2019: unresolved external symbol “public: void \_\_cdecl ULineBatchComponent::DrawLines(class TArray\<struct FBatchedLine,class FDefaultAllocator\> const &)” (?DrawLines@ULineBatchComponent@@QEAAXAEBV?$TArray@UFBatchedLine@@VFDefaultAllocator@@@@@Z) referenced in function “public: virtual void \_\_cdecl AActorFibers::BeginPlay(void)” (?BeginPlay@AActorFibers@@UEAAXXZ)

Here’s the small fragment of code I’m trying to use :  
UWorld\* currentWorld = GetWorld();  
ULineBatchComponent\* const LineBatcher = currentWorld-\>PersistentLineBatcher;

```
int numberOfLinez = 5000000;
TArray<struct FBatchedLine, FDefaultAllocator > linez;
linez.Empty();
for (int i = 0; i < numberOfLinez; ++i)
{
    linez.Add(FBatchedLine(FVector(0.0f + i*0.05, 0.0f, 0.0f), FVector(0.0f + (i + 1)*0.05, 0.0f, 0.0f), FColor(255.0f, 0.0f, 0.0f), 100.0f,1.0f,8));
}
LineBatcher->DrawLines(linez);

```

Everything to me should be in order, but it’s clearly not, and I have no idea why, especially since I can use DrawLine…

Any help would be greatly appreciated, and if someone has other suggestions to my line drawing as an alternative to DrawLines, I’m all ears.

Thanks !

---

<div class="post-metadata">

**Author:** ![Rama](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/rama/32/882413_2.png) [@Rama](https://forums.unrealengine.com/u/Rama)\
**Post date:** [April 21, 2015, 8:52am UTC](https://forums.unrealengine.com/t/how-to-use-drawlines/315549/2 "2015-04-21T08:52:38Z")

</div>

#Epic Please Expose

Sounds like this function is not yet ENGINE\_API, Epic please expose this!

Rama

---

<div class="post-metadata">

**Author:** ![Rama](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/rama/32/882413_2.png) [@Rama](https://forums.unrealengine.com/u/Rama)\
**Post date:** [April 21, 2015, 8:54am UTC](https://forums.unrealengine.com/t/how-to-use-drawlines/315549/3 "2015-04-21T08:54:40Z")

</div>

#Solution C++

You can get the line batcher yourself and draw as many lines as you want!

Put this in a .cpp somewheres to test!

```
static ULineBatchComponent* GetDebugLineBatcher( const UWorld* InWorld, bool bPersistentLines, float LifeTime, bool bDepthIsForeground )
{
	return (InWorld ? (bDepthIsForeground ? InWorld->ForegroundLineBatcher : (( bPersistentLines || (LifeTime > 0.f) ) ? InWorld->PersistentLineBatcher : InWorld->LineBatcher)) : NULL);
}

```

#Draw Debug Box  
make a .h for this function below, the above one stays as static in .cpp (or you could make it .h if you wanted to)

```
void DrawDebugBox(const UWorld* InWorld, FVector const& Center, FVector const& Box, FColor const& Color, bool bPersistentLines, float LifeTime, uint8 DepthPriority)
{
	// no debug line drawing on dedicated server
	if (GEngine->GetNetMode(InWorld) != NM_DedicatedServer)
	{
		// this means foreground lines can't be persistent 
		ULineBatchComponent* const LineBatcher = GetDebugLineBatcher( InWorld, bPersistentLines, LifeTime, (DepthPriority == SDPG_Foreground) );		
		if(LineBatcher != NULL)
		{
			float LineLifeTime = (LifeTime > 0.f)? LifeTime : LineBatcher->DefaultLifeTime;

			LineBatcher->DrawLine(Center + FVector( Box.X, Box.Y, Box.Z), Center + FVector( Box.X, -Box.Y, Box.Z), Color, DepthPriority, 0.f, LineLifeTime);
			LineBatcher->DrawLine(Center + FVector( Box.X, -Box.Y, Box.Z), Center + FVector(-Box.X, -Box.Y, Box.Z), Color, DepthPriority, 0.f, LineLifeTime);

```

**Navigate to DrawDebugHelpers.cpp to find the rest of this C++ code (this is a legal matter ❤ Rama)**

#Enjoy!

#❤

Rama

---

<div class="post-metadata">

**Author:** ![LPLedoux](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@LPLedoux](https://forums.unrealengine.com/u/LPLedoux)\
**Post date:** [April 23, 2015, 1:51pm UTC](https://forums.unrealengine.com/t/how-to-use-drawlines/315549/4 "2015-04-23T13:51:15Z")

</div>

Thanks a lot, appreciate the response !

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_59bca5ba](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_59bca5ba](https://forums.unrealengine.com/u/anonymous_user_59bca5ba)\
**Post date:** [February 9, 2016, 7:39pm UTC](https://forums.unrealengine.com/t/how-to-use-drawlines/315549/5 "2016-02-09T19:39:56Z")

</div>

I also hit this. If you look at the implementation of that function it’s rather simple and you are able to inline it yourself in your code like:  
LineBatcher-\>BatchedLines.Append(linez);  
LineBatcher-\>MarkRenderStateDirty();

Would be nice to be able to all it directly, but this works.

---

<div class="post-metadata">

**Author:** ![SuryaPrakashModi](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@SuryaPrakashModi](https://forums.unrealengine.com/u/SuryaPrakashModi)\
**Post date:** [May 25, 2021, 7:22am UTC](https://forums.unrealengine.com/t/how-to-use-drawlines/315549/6 "2021-05-25T07:22:08Z")

</div>

watch this. [How To Do Line Tracing Using C++ In Unreal Engine - YouTube](https://youtu.be/LWeQicz_teo)

---

<div class="post-metadata">

**Author:** ![Skulldug](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/skulldug/32/1194522_2.png) [@Skulldug](https://forums.unrealengine.com/u/Skulldug)\
**Post date:** [June 9, 2025, 6:31pm UTC](https://forums.unrealengine.com/t/how-to-use-drawlines/315549/7 "2025-06-09T18:31:41Z")

</div>

Please save my sanity Rama.. This is no longer compiling in 5.6  
ForegroundLineBatcher’: is not a member of ‘UWorld’  
‘PersistentLineBatcher’: is not a member of ‘UWorld’  
‘LineBatcher’: is not a member of ‘UWorld’  
This is from DoNs flying ai plugin any idea what is causing this ?
