Download

Draw line (Not debug)

Hey guys!
I’m trying to build a waypoint system. This is what it looks like atm:
bdd44ae17dbf99def8913f0602f49ac19bccd9d9.jpeg

As you can see, there are debug lines connecting to each of the points. HOWEVER this doesn’t work: The only way (I know) to delete these lines is to clear all of them - this is not the desired effect.

Is there a way to either have a line component (That you can move or delete or whatever), or even better a way to delete specific lines? I doubt the latter is even a remote possibility, but what about the former?

Right now the only way to do this is every time I want to delete a line, I have to redraw all of the debug stuff in the entire game. Not gucci.

Thanks!

What function are you using currently to draw lines? How do you store which lines to draw?

If you’re using DrawDebugLine, you can re-decide each tick which lines you want to draw. I suggest looking into SpringArmComponent.cpp, it uses DrawDebugDirectionalArrow to draw lines in the editor between its endpoints, but DrawDebugLine would work as well.

Yeah, I use DrawDebugLine.
I was thinking it would be nice to not draw all the lines each tick, but it seems like I’ll have to. I’ve tried the arrow thing, but I couldn’t find a way to thicken the arrow. shrugs
Thanks!

You could create a component for that so it will be usable in editor and in a packaged game (I use one for exactly that, waypoints and paths). Just inherit from ‘FPrimitiveSceneProxy’ and override the ‘DrawDynamicElements’ method. The method provides you with a 'FPrimitiveDrawInterface* PDI, there you can draw you shapes too like points:


PDI->DrawPoint(<location>, <color>, <size>, 0); // 0 is the depth priority group

Or if you want to draw a nice error you can use the method I’m using:


void DrawArrow(FPrimitiveDrawInterface* PDI, const FVector& Start, const FVector& End, const FLinearColor& Color, uint8 DepthPriorityGroup, float ArrowSizeSqrt = 0.0f, float Thickness = 0.0f, float DepthBias = 0.0f, bool bScreenSpace = false)
{
    FVector Dir = End - Start;
    Dir.Normalize();

    // Draw green line and the arrow
    PDI->DrawLine(Start, End, Color, 0, Thickness);

    FVector Up(0, 0, 1);
    FVector Right = Dir ^ Up;
    if (!Right.IsNormalized())
    {
        Dir.FindBestAxisVectors(Up, Right);
    }
    FVector Origin = FVector::ZeroVector;
    FMatrix TM;
    // get matrix with dir/right/up
    TM.SetAxes(&Dir, &Right, &Up, &Origin);
    PDI->DrawLine(End, End + TM.TransformPosition(FVector(-ArrowSizeSqrt, ArrowSizeSqrt, 0)), Color, DepthPriorityGroup, Thickness);
    PDI->DrawLine(End, End + TM.TransformPosition(FVector(-ArrowSizeSqrt, -ArrowSizeSqrt, 0)), Color, DepthPriorityGroup, Thickness);
}

Not that you have your class that makes all the drawing you have to create a new ‘UPrimitiveComponent’ child class and override the ‘CreateSceneProxy’ method where you return an instance of your FPrimitiveDrawInterface you created earlier. Your component should then decide when to be drawn using ‘ShouldRecreateProxyOnUpdateTransform’ or managing bounds in ‘CalcBounds’, bounds are vital because your component wont be drawn if the bounds are our of the camera.

Hope this can help you