5.1 UKismetSystemLibrary::All Trace Don't Work in CPP

EDrawDebugTrace::ForDuration return right value
EDrawDebugTrace::None return wrong value
In Actor Component
I don’t understand

It seems like you are using Unreal Engine’s EDrawDebugTrace for debugging purposes, and you’re encountering issues with the return values when using ForDuration and None options. Let me clarify the usage of these options.

  1. EDrawDebugTrace::ForDuration:
  • When you use EDrawDebugTrace::ForDuration, you are instructing Unreal Engine to draw the debug trace for a specified duration. This can be useful for visualizing the trace in the game world for a specific amount of time.Example:

cppCopy code

UGameplayStatics::DrawDebugTrace(GetWorld(), Start, End, TraceChannel, false, TraceColor, false, Duration);

Here, Duration is the time for which the debug trace will be visible in the game world.
2. EDrawDebugTrace::None:

  • On the other hand, when you use EDrawDebugTrace::None, you are essentially telling Unreal Engine not to draw the debug trace in the game world. This option is often used when you want to perform a trace for functionality (e.g., detecting hits), but you don’t want to visualize the trace.Example:

cppCopy code

FHitResult HitResult;
bool bHit = GetWorld()->LineTraceSingleByChannel(HitResult, Start, End, TraceChannel);

In this case, the trace is performed, but there is no visualization in the game world.

If you’re experiencing issues with the return values, you might want to check the following:

  • ForDuration Return Value: Ensure that the return value of the function using EDrawDebugTrace::ForDuration is appropriate for your use case. This function generally returns a boolean indicating whether the trace hit something or not.
  • None Return Value: For EDrawDebugTrace::None, you might not be getting the debug visualization, but the actual trace is still being performed. Check the return values of the trace function (e.g., LineTraceSingleByChannel) to see if it’s detecting hits as expected.