# C++ Line Trace Debug Color

**URL:** <https://forums.unrealengine.com/t/c-line-trace-debug-color/443795>\
**Category:** Rendering\
**Tags:** Trace, debug, line, unreal-engine, color, CPP, question\
**Created:** [February 20, 2019, 8:13pm UTC](https://forums.unrealengine.com/t/c-line-trace-debug-color/443795 "2019-02-20T20:13:01Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Geezius](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Geezius](https://forums.unrealengine.com/u/Geezius)\
**Post date:** [February 20, 2019, 8:13pm UTC](https://forums.unrealengine.com/t/c-line-trace-debug-color/443795/1 "2019-02-20T20:13:01Z")

</div>

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](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/7/d/27d9ae8129537cb750aad32b7280f53468f22c99.png)

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

Thank You,

Ryan

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_4ab007e8](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_4ab007e8](https://forums.unrealengine.com/u/anonymous_user_4ab007e8)\
**Post date:** [August 26, 2019, 1:33pm UTC](https://forums.unrealengine.com/t/c-line-trace-debug-color/443795/2 "2019-08-26T13:33:06Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![RockyDias](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@RockyDias](https://forums.unrealengine.com/u/RockyDias)\
**Post date:** [July 22, 2021, 1:06pm UTC](https://forums.unrealengine.com/t/c-line-trace-debug-color/443795/3 "2021-07-22T13:06:26Z")

</div>

You are looking for: [DrawDebugLine | Unreal Engine Documentation](https://docs.unrealengine.com/4.26/en-US/API/Runtime/Engine/DrawDebugLine/)

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

---

<div class="post-metadata">

**Author:** ![Cevolord](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Cevolord](https://forums.unrealengine.com/u/Cevolord)\
**Post date:** [February 22, 2024, 11:56pm UTC](https://forums.unrealengine.com/t/c-line-trace-debug-color/443795/4 "2024-02-22T23:56:35Z")

</div>

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.

 ![Screenshot 2024-02-23 031407](https://d3kjluh73b9h9o.cloudfront.net/original/4X/9/6/a/96a22c1967c18e5d31f8976d26084bbd11791c27.png)

---

<div class="post-metadata">

**Author:** ![RockyDias](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@RockyDias](https://forums.unrealengine.com/u/RockyDias)\
**Post date:** [February 26, 2024, 10:53am UTC](https://forums.unrealengine.com/t/c-line-trace-debug-color/443795/5 "2024-02-26T10:53:15Z")

</div>

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++:

```auto
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:

```auto
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.

---

<div class="post-metadata">

**Author:** ![Snow901](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Snow901](https://forums.unrealengine.com/u/Snow901)\
**Post date:** [March 2, 2025, 8:13pm UTC](https://forums.unrealengine.com/t/c-line-trace-debug-color/443795/6 "2025-03-02T20:13:32Z")

</div>

I recently found

```auto
#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:

```auto
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);

```

---

<div class="post-metadata">

**Author:** ![sergio.gardeazabal](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/sergio.gardeazabal/32/924296_2.png) [@sergio.gardeazabal](https://forums.unrealengine.com/u/sergio.gardeazabal)\
**Post date:** [March 2, 2025, 8:55pm UTC](https://forums.unrealengine.com/t/c-line-trace-debug-color/443795/7 "2025-03-02T20:55:47Z")

</div>

In addition, Since UE 5.4 the Chaos Visual debugger is also available (the 5.5 version has more features, but in 5.4 the basic functionality is available).

We record all scene queries done via the UWorld API, you can not only see the query itself visually, but you can also click on it and see all the parameter used with the query.

> **[Chaos Visual Debugger - User Guide for UE 5.5 | Tutorial](https://dev.epicgames.com/community/learning/tutorials/bZPZ/unreal-engine-chaos-visual-debugger-user-guide-for-ue-5-5#scenequeriesvisualizationflags)**
>
> User Guide for the Beta release of the Chaos Visual Debugger for UE 5.5. The tool to Debug Physics in Unreal Engine

The visualization is not in the game viewport though.
