UKismetSystemLibrary::SphereTraceSingleForObjects
#include "Kismet/KismetSystemLibrary.h"
Access: public
Specifiers: staticBlueprintCallable
Description
Sweeps a sphere 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 'Sphere Trace For Objects'.
Caveats & Gotchas
- • A common bug is forgetting that ObjectTypes needs at least one entry — with an empty array the trace effectively finds nothing, but doesn't warn.
- • Object Type is set per-component in the collision profile ('Object Type' dropdown), independent of the channel responses used by SphereTraceSingle — a component can block ECC_Visibility yet still be invisible to this function if its Object Type isn't in the list.
- • Radius uses the same sphere-sweep cost as SphereTraceSingle; querying against many Object Types doesn't multiply the trace cost, since it's still one sweep with a combined query mask.
Signature
static ENGINE_API bool SphereTraceSingleForObjects(const UObject* WorldContextObject, const FVector Start, const FVector End, float Radius, 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 sphere to sweep. | — |
| 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 sphere looking only for pickups tagged as WorldDynamic C++
FHitResult Hit;
TArray<TEnumAsByte<EObjectTypeQuery>> ObjectTypes;
ObjectTypes.Add(UEngineTypes::ConvertToObjectType(ECC_WorldDynamic));
TArray<AActor*> ActorsToIgnore;
ActorsToIgnore.Add(this);
const FVector Start = GetActorLocation();
const FVector End = Start + GetActorForwardVector() * 500.f;
bool bHit = UKismetSystemLibrary::SphereTraceSingleForObjects(this, Start, End, 30.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?