UKismetSystemLibrary::SphereTraceSingle
#include "Kismet/KismetSystemLibrary.h"
Access: public
Specifiers: staticUFUNCTIONBlueprintCallable
Description
Sweeps a sphere of the given Radius from Start to End against the given Trace Channel and returns the first blocking hit encountered. Exposed to Blueprint as 'Sphere Trace By Channel'.
Caveats & Gotchas
- • This is a swept shape trace, not a stationary overlap — Radius is the sphere size and the hit is the first blocking contact anywhere between Start and End, unlike SphereOverlapActors/Components which test a single fixed position.
- • TraceChannel is a Trace Channel, not an Object Type — use SphereTraceSingleForObjects if you need to query by Object Type instead.
- • DrawDebugType visualization only appears in builds with ENABLE_DRAW_DEBUG defined; it's compiled out in shipping.
Signature
static ENGINE_API bool SphereTraceSingle(const UObject* WorldContextObject, const FVector Start, const FVector End, float Radius, 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 sweep in world space. | — |
| End | const FVector | End point of the sweep in world space. | — |
| Radius | float | Radius of the sphere swept along the segment. | — |
| 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 sweep 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
Sweep a sphere forward for a wider hit check than a line trace C++
FHitResult Hit;
TArray<AActor*> ActorsToIgnore;
ActorsToIgnore.Add(this);
const FVector Start = GetActorLocation();
const FVector End = Start + GetActorForwardVector() * 1000.f;
bool bHit = UKismetSystemLibrary::SphereTraceSingle(this, Start, End, 25.f, 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?