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”.
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++:
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);
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.
The visualization is not in the game viewport though.