C++ Line Trace Debug Color

I have successfully used both Trace Tags and DrawDebugLine to render debug lines, but I have an issue.

Is there a function for a C++ debug line that acts like the blueprint version (color features)? Trace Tags seem to only be white. I can’t find a way to adjust color for these. I can draw a debug line with a different color using DrawDebugLine, but it does not change color when a hit is detected. I can’t find any parameters that suggest this is possible.

In blueprint, LineTraceByChannel has “Trace Color” AND “Trace Hit Color”.

269152-2019-02-20-13-09-47-platformercpp-unreal-editor.png

I need “Trace Hit Color” in C++.

Thank You,

Ryan

When constructing the DrawDebug line , you can add a FColor and select the RGB Value

You are looking for: DrawDebugLine | Unreal Engine Documentation

Example:
if(GetWorld())
DrawDebugLine(GetWorld(), StartLocation, EndLocation, FColor(255, 0, 0), false, 5, 1, 3.f);

Could you please read the topic and question carefully before replying ? He is asking for Trace hit color not debug line color.
you can add another debug at the hit location with different 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.