RealDocs

UWorld::SweepSingleByChannel

function Engine Since 4.0
#include "Engine/World.h"
Access: public Specifiers: const

Description

Sweeps a collision shape from Start to End and returns the first blocking hit. More accurate than a line trace when testing whether a volume (capsule, sphere, or box) can pass through space.

Signature

bool SweepSingleByChannel( struct FHitResult& OutHit, const FVector& Start, const FVector& End, const FQuat& Rot, ECollisionChannel TraceChannel, const FCollisionShape& CollisionShape, const FCollisionQueryParams& Params = FCollisionQueryParams::DefaultQueryParam, const FCollisionResponseParams& ResponseParam = FCollisionResponseParams::DefaultResponseParam ) const

Parameters

Name Type Description Default
OutHit struct FHitResult& Receives the first blocking hit result.
Start const FVector& World-space start position of the swept shape's center.
End const FVector& World-space end position of the swept shape's center.
Rot const FQuat& Rotation of the swept shape. Use FQuat::Identity for no rotation.
TraceChannel ECollisionChannel Collision channel determining which components can be hit.
CollisionShape const FCollisionShape& The shape to sweep. Create with FCollisionShape::MakeSphere(), MakeCapsule(), or MakeBox().
Params const FCollisionQueryParams& Additional query options. FCollisionQueryParams::DefaultQueryParam
ResponseParam const FCollisionResponseParams& Override collision response settings. FCollisionResponseParams::DefaultResponseParam

Return Type

bool

Caveats & Gotchas

  • Use FCollisionShape::MakeSphere(Radius), MakeCapsule(Radius, HalfHeight), or MakeBox(HalfExtents) to construct the shape — there is no useful default constructor.
  • FQuat::Identity is the correct value for Rot when shape orientation doesn't matter (spheres) or when you want an axis-aligned sweep.
  • Sweep queries are more expensive than line traces. Cache FCollisionShape and FCollisionQueryParams if calling this frequently per frame.

Example

Sphere sweep forward to check for obstacles C++
FHitResult Hit;
FCollisionShape Sphere = FCollisionShape::MakeSphere(30.f);
FCollisionQueryParams Params;
Params.AddIgnoredActor(this);

bool bBlocked = GetWorld()->SweepSingleByChannel(
	Hit,
	GetActorLocation(),
	GetActorLocation() + GetActorForwardVector() * 500.f,
	FQuat::Identity,
	ECC_Pawn,
	Sphere,
	Params
);

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.