UKismetSystemLibrary::CapsuleTraceSingleForObjects
#include "Kismet/KismetSystemLibrary.h"
Access: public
Specifiers: staticBlueprintCallable
Description
Sweeps a capsule from Start to End and returns the first hit against a component whose collision responds to one of the given Object Types. Exposed to Blueprint as 'Capsule Trace For Objects'.
Caveats & Gotchas
- • HalfHeight follows UCapsuleComponent's center-to-hemisphere-tip convention — reuse the character's CapsuleComponent values directly to match its actual collision shape.
- • ObjectTypes governs matching here instead of a Trace Channel, so components that only respond to a specific channel (but have no matching Object Type) will be missed entirely.
- • This capsule can't be reoriented off its local Z axis, same limitation as CapsuleTraceSingle — there's no Orientation parameter.
Signature
static ENGINE_API bool CapsuleTraceSingleForObjects(const UObject* WorldContextObject, const FVector Start, const FVector End, float Radius, float HalfHeight, const TArray<TEnumAsByte<EObjectTypeQuery> > & ObjectTypes, 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. | — |
| ObjectTypes | const TArray<TEnumAsByte<EObjectTypeQuery>>& | Array of Object Types to trace 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 character-sized capsule looking for pawns C++
FHitResult Hit;
TArray<TEnumAsByte<EObjectTypeQuery>> ObjectTypes;
ObjectTypes.Add(UEngineTypes::ConvertToObjectType(ECC_Pawn));
TArray<AActor*> ActorsToIgnore;
ActorsToIgnore.Add(this);
const FVector Start = GetActorLocation();
const FVector End = Start + GetActorForwardVector() * 200.f;
bool bHit = UKismetSystemLibrary::CapsuleTraceSingleForObjects(this, Start, End, 34.f, 88.f, ObjectTypes, 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?