RealDocs

UKismetSystemLibrary::SphereTraceSingleByProfile

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

Description

Sweeps a sphere from Start to End against the world using a named Collision Profile and returns the first blocking hit. Exposed to Blueprint as 'Sphere Trace By Profile'.

Caveats & Gotchas

  • • ProfileName selects an entire response template (e.g. 'Pawn', 'Ragdoll', 'Vehicle') rather than a single channel — verify what that profile blocks vs overlaps in Project Settings before relying on the result.
  • • Custom project-defined profiles won't exist on a fresh clone of the project's config unless the DefaultEngine.ini collision section is checked in — a profile that works on one machine can silently behave differently (or fall back to default) on another if config isn't synced.
  • • As with the other sphere sweeps, bTraceComplex against static meshes with per-poly collision is considerably more expensive than the default simplified collision test.

Signature

static ENGINE_API bool SphereTraceSingleByProfile(const UObject* WorldContextObject, const FVector Start, const FVector End, float Radius, UPARAM(Meta=(GetOptions=GetCollisionProfileNames)) FName ProfileName, 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 sphere to sweep. —
ProfileName FName The collision profile used to determine which components to hit. —
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 sphere using the Pawn collision profile C++
FHitResult Hit;
TArray<AActor*> ActorsToIgnore;
ActorsToIgnore.Add(this);

const FVector Start = GetActorLocation();
const FVector End = Start + GetActorForwardVector() * 500.f;

bool bHit = UKismetSystemLibrary::SphereTraceSingleByProfile(this, Start, End, 30.f, FName("Pawn"), 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.