UKismetSystemLibrary::SphereTraceMultiForObjects
#include "Kismet/KismetSystemLibrary.h"
Access: public
Specifiers: staticBlueprintCallable
Description
Sweeps a sphere from Start to End and returns every hit against components whose collision responds to one of the given Object Types. Exposed to Blueprint as 'Multi Sphere Trace For Objects'.
Caveats & Gotchas
- • OutHits collects every matching component along the whole sweep, so a wide-radius trace through a cluster of dynamic actors can return a large array — filter or sort in Blueprint/C++ afterward if you only need the closest.
- • ObjectTypes and TraceChannel are mutually exclusive filtering models on this family of functions — there's no way to combine 'respond to this channel' and 'is this object type' in a single call.
- • As with SphereTraceMulti, hits are sorted along the sweep direction but there's no blocking-hit concept for Object Type queries — every match is included regardless of position in the list.
Signature
static ENGINE_API bool SphereTraceMultiForObjects(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, TArray<FHitResult>& OutHits, 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. | — |
| OutHits | TArray<FHitResult>& | All hits found along the sweep. | — |
| 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 for every dynamic actor along a path C++
TArray<FHitResult> Hits;
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::SphereTraceMultiForObjects(this, Start, End, 30.f, ObjectTypes, false, ActorsToIgnore, EDrawDebugTrace::ForDuration, Hits, true); See Also
Tags
Version History
Introduced in: 4.0
| Version | Status | Notes |
|---|---|---|
| 5.6 | stable | — |
Feedback
Was this helpful?