C++ Line Trace Debug Color

Of course, I will answer 3 years later, but in a better way.

I’m pretty sure he’s asking if there is a function like (BP) LineTraceByChannel, but for C++. Seems like he knows how to use it. So, here is how you use LineTraceByChannel in C++:

void UInteractionComponent::TestTrace()
{
  FHitResult HitResult;
  const FVector TraceStart = CharacterRef->GetActorLocation();
  const FVector TraceEnd = CharacterRef->GetActorLocation() - FVector(0, 0, 200);

  if (GetWorld()->LineTraceSingleByChannel(
      HitResult,
      TraceStart,
      TraceEnd,
      ECC_Visibility
  ))
  {
      // Do something
  }
}

However, you also want to see the colors. So you can use this, that is really the same than blueprint LineTraceByChannel node:

void UInteractionComponent::TestTrace()
{
    FHitResult HitResult;
    const FVector TraceStart = CharacterRef->GetActorLocation();
    const FVector TraceEnd = CharacterRef->GetActorLocation() - FVector(0, 0, 200);
    TArray<AActor*> ActorsToIgnore;
    FColor ColorBeforeHit = FColor::Red;
    FColor ColorAfterHit = FColor::Red;
    float ColorsLifeTime = 5.f;
    
    if (UKismetSystemLibrary::LineTraceSingle(
        GetWorld(),
        TraceStart,
        TraceEnd,
        UEngineTypes::ConvertToTraceType(ECC_Visibility),
        false,
        ActorsToIgnore,
        EDrawDebugTrace::ForDuration,
        HitResult,
        true,
        ColorBeforeHit,
        ColorAfterHit,
        ColorsLifeTime
    ))
    {
        // Do something
    }
}

By the way, note that you can can hover any node and check what library is this comming from. This way you can google it and find the function.