I recently found
#include "KismetTraceUtils.h"
void DrawDebugLineTraceSingle(
const UWorld* World,
const FVector& Start,
const FVector& End,
EDrawDebugTrace::Type DrawDebugType,
bool bHit,
const FHitResult& OutHit,
FLinearColor TraceColor,
FLinearColor TraceHitColor,
float DrawTime);
Which is probably what OP was looking for to replicate the same functionality in code that can be done through BP.
I’m using 5.4, but I’d guess its available in earlier versions of the engine as well.
From my understanding, an example usage of it works like below:
FHitResult Hit(1.f);
float TraceDistance = 500.f; float TraceDuration = 5.f;
FVector Start = GetActorLocation();
FVector End = Start + GetActorForwardVector() * TraceDistance;
FCollisionQueryParams QueryParams;
QueryParams.AddIgnoredActor(this);
UWorld* World = GetWorld();
// do the line trace
bool bHit = World->LineTraceSingleByChannel(Hit, Start, End, ECC_Visibility, QueryParams);
// now draw a debug line using the result of the trace
DrawDebugLineTraceSingle(World, Start, End, EDrawDebugTrace::ForDuration, bHit, Hit, FColor::Red, FColor::Green, TraceDuration);