UKismetSystemLibrary::CapsuleTraceSingle
#include "Kismet/KismetSystemLibrary.h"
Access: public
Specifiers: staticBlueprintCallable
Description
Sweeps a capsule from Start to End against the given Trace Channel and returns the first blocking hit encountered. Exposed to Blueprint as 'Capsule Trace By Channel'.
Caveats & Gotchas
- • HalfHeight is measured from the capsule's center to the tip of a hemisphere endcap (matching UCapsuleComponent's convention), not the height of the cylindrical section alone — using a character capsule's raw CapsuleHalfHeight value here matches its actual collision shape.
- • The capsule sweeps upright along its own local Z axis only — there's no orientation parameter, so you can't sweep a capsule lying on its side with this function.
- • TraceChannel is a Trace Channel, not an Object Type — use CapsuleTraceSingleForObjects to filter by object classification instead.
Signature
static ENGINE_API bool CapsuleTraceSingle(const UObject* WorldContextObject, const FVector Start, const FVector End, float Radius, float HalfHeight, 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* | World context. | — |
| Start | const FVector | Start of the sweep. | — |
| End | const FVector | End of the sweep. | — |
| Radius | float | Radius of the capsule to sweep. | — |
| HalfHeight | float | Distance from the center of the capsule to the tip of a hemisphere endcap. | — |
| TraceChannel | ETraceTypeQuery | The trace channel to test against. | — |
| bTraceComplex | bool | True to test against complex collision, false to test against simplified collision. | — |
| ActorsToIgnore | const TArray<AActor*>& | Actors to exclude from the trace. | — |
| DrawDebugType | EDrawDebugTrace::Type | Debug draw mode. | — |
| OutHit | FHitResult& | Properties of the trace hit. | — |
| bIgnoreSelf | bool | Whether to ignore the world context actor itself. | — |
| TraceColor | FLinearColor | Debug draw color for the trace. | FLinearColor::Red |
| TraceHitColor | FLinearColor | Debug draw color for hits. | FLinearColor::Green |
| DrawTime | float | How long the debug draw persists, in seconds. | 5.0f |
Return Type
bool Example
Sweep a capsule matching a character's collision shape C++
FHitResult Hit;
TArray<AActor*> ActorsToIgnore;
ActorsToIgnore.Add(this);
const FVector Start = GetActorLocation();
const FVector End = Start + GetActorForwardVector() * 200.f;
bool bHit = UKismetSystemLibrary::CapsuleTraceSingle(this, Start, End, 34.f, 88.f, UEngineTypes::ConvertToTraceType(ECC_Pawn), false, ActorsToIgnore, EDrawDebugTrace::ForDuration, Hit, true); See Also
Tags
Version History
Introduced in: 4.0
| Version | Status | Notes |
|---|---|---|
| 5.6 | stable | — |
Feedback
Was this helpful?