How to use DrawLines?

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;
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));

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 !

#Epic Please Expose

Sounds like this function is not yet ENGINE_API, Epic please expose this!


#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 :heart: Rama)




Thanks a lot, appreciate the response !

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:

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

watch this. How To Do Line Tracing Using C++ In Unreal Engine - YouTube