UKismetSystemLibrary::LineTraceSingle
#include "Kismet/KismetSystemLibrary.h"
Access: public
Specifiers: staticUFUNCTIONBlueprintCallable
Description
Performs a line trace between Start and End against the given Trace Channel and returns the first blocking hit encountered. Exposed to Blueprint as 'Line Trace By Channel'.
Caveats & Gotchas
- • TraceChannel is a Trace Channel (Project Settings > Collision > Trace Channels), not an Object Type like the Overlap family in this same class — a component set to Overlap (not Block) for that channel never registers as a hit here.
- • DrawDebugType only draws anything in builds where ENABLE_DRAW_DEBUG is defined (editor/development); the debug visualization is compiled out entirely in shipping builds.
- • bIgnoreSelf only has an effect if WorldContextObject resolves to an actor or component with an owning actor — it does nothing if WorldContextObject is an unrelated UObject.
Signature
static ENGINE_API bool LineTraceSingle(const UObject* WorldContextObject, const FVector Start, const FVector End, ETraceTypeQuery TraceChannel, bool bTraceComplex, const TArray<AActor*>& ActorsToIgnore, EDrawDebugTrace::Type DrawDebugType, FHitResult& OutHit, bool bIgnoreSelf, FLinearColor TraceColor = FLinearColor::Red, FLinearColor TraceHitColor = FLinearColor::Green, float DrawTime = 5.0f) Parameters
| Name | Type | Description | Default |
|---|---|---|---|
| WorldContextObject | const UObject* | Object used to resolve which UWorld to run the trace in. | — |
| Start | const FVector | Start point of the trace in world space. | — |
| End | const FVector | End point of the trace in world space. | — |
| TraceChannel | ETraceTypeQuery | Trace Channel to test against (Project Settings > Collision > Trace Channels). | — |
| bTraceComplex | bool | True to test against per-poly complex collision, false to test against simplified collision. | — |
| ActorsToIgnore | const TArray<AActor*>& | Actors excluded from the trace. | — |
| DrawDebugType | EDrawDebugTrace::Type | Debug draw mode for visualizing the trace. | — |
| OutHit | FHitResult& | Detailed information about the first blocking hit, if any. | — |
| bIgnoreSelf | bool | If true, ignores the actor owning WorldContextObject. | — |
| TraceColor | FLinearColor | Color used to draw the non-hit portion of the trace when debug drawing is enabled. | FLinearColor::Red |
| TraceHitColor | FLinearColor | Color used to draw from the hit point onward when debug drawing is enabled. | FLinearColor::Green |
| DrawTime | float | How long the debug draw persists, in seconds. | 5.0f |
Return Type
bool Example
Trace forward from an actor and read the hit result C++
FHitResult Hit;
TArray<AActor*> ActorsToIgnore;
ActorsToIgnore.Add(this);
const FVector Start = GetActorLocation();
const FVector End = Start + GetActorForwardVector() * 1000.f;
bool bHit = UKismetSystemLibrary::LineTraceSingle(this, Start, End, UEngineTypes::ConvertToTraceType(ECC_Visibility), false, ActorsToIgnore, EDrawDebugTrace::ForDuration, Hit, true); Tags
Version History
Introduced in: 4.0
| Version | Status | Notes |
|---|---|---|
| 5.6 | stable | — |
Feedback
Was this helpful?