RealDocs

UKismetSystemLibrary::BoxTraceSingleForObjects

function Engine Blueprint Since 4.0
#include "Kismet/KismetSystemLibrary.h"
Access: public Specifiers: staticBlueprintCallable

Description

Sweeps an oriented box 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 'Box Trace For Objects'.

Caveats & Gotchas

  • Orientation still applies the full box rotation even though the filtering is by Object Type — an unrotated box parameter with a non-identity Orientation argument will still sweep at an angle.
  • ObjectTypes replaces TraceChannel entirely on this overload; there's no way to also restrict by a specific channel's response in the same call.
  • HalfSize is a half-extent, matching UBoxComponent's BoxExtent convention — doubling it doubles the swept volume on that axis, not just the visual box size.

Signature

static ENGINE_API bool BoxTraceSingleForObjects(const UObject* WorldContextObject, const FVector Start, const FVector End, const FVector HalfSize, const FRotator Orientation, 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.
HalfSize const FVector Distance from the center of the box along each axis.
Orientation const FRotator Orientation of the box.
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 box looking for physics bodies C++
FHitResult Hit;
TArray<TEnumAsByte<EObjectTypeQuery>> ObjectTypes;
ObjectTypes.Add(UEngineTypes::ConvertToObjectType(ECC_PhysicsBody));

TArray<AActor*> ActorsToIgnore;
ActorsToIgnore.Add(this);

const FVector Start = GetActorLocation();
const FVector End = Start + GetActorForwardVector() * 300.f;
const FVector HalfSize(50.f, 25.f, 25.f);

bool bHit = UKismetSystemLibrary::BoxTraceSingleForObjects(this, Start, End, HalfSize, GetActorRotation(), ObjectTypes, false, ActorsToIgnore, EDrawDebugTrace::ForDuration, Hit, true);

Version History

Introduced in: 4.0

Version Status Notes
5.6 stable

Feedback

Was this helpful?

Suggest an edit

Select a field above to begin editing.