DrawDebugLine lost it's ability to be persistent?

For a long time already, since U4.16 i used this function:

DrawDebugLine(
		         GetWorld()
	                , FVector(from[0], from[1], from[2])
			, FVector(to[0], to[1], to[2])
			, FColor(color[0], color[1], color[2], color[3])
			, /*bPersistentLines=*/true /*make line last for entire session*/
			);

Recently (at UE4.20.3) i noticed that although i set bPersistentLines to true, lines fade away. Is there an alternative new API? Is this a bug? Is this in purpose?

Hi Felix,

Could you give me some steps so that I could attempt to reproduce this? I.e. when are you calling DrawDebugLine, from what type of class, etc.

Thank you for the response!

I call DrawDebugLine on expense of the processing time of the StaticMeshActor Tick() method. The “from” vector is Player0 camera position. The “to” vector is this StaticMeshActor’s current position. Truth be told, the full call stack consists of some function i call from the Tick(), which receives a delegate solely with DrawDebugLine inside, and then calls it. But why should it matter?

Worth mentioning, that this system works perfectly in 4.16, and it’s not that it doesn’t draw in 4.20, or throws exception. The bPersistentLines=true is ignored, that is a problem. I can not imagine possible reason for that except of some deep under-the-hood code that resets it to false. The line lifetime option works fine by the way. So, i am able to delay fading, but not to disable it, or i should rather say, enable session-long lifetime of the line.

Hi Felix,

I’ve looked into this more and can confirm that this is a bug. Looking at the engine source, it appears as though bPersistentLines stays intact throughout the call to draw the line but the lifetime is forced to the default line lifetime of one second if the passed in lifetime is less than zero (which would be the case if you’re only passing in just enough parameters to make bPersistentLines true).

I’ve gone ahead and filed the bug internally. Once it is made public, you can follow its progress on the issues site. In the meantime, here is a quick little workaround you can use to draw persistent lines:

static void DrawPersistentLine(UWorld *World, const FVector &Start, const FVector &End, const FColor &Color)
{
	if (World && World->PersistentLineBatcher)
	{
		World->PersistentLineBatcher->DrawLine(Start, End, Color, SDPG_World);
	}
}
1 Like

Thank you. Will wait for 4.21