UKismetSystemLibrary::SphereOverlapActors
#include "Kismet/KismetSystemLibrary.h"
Access: public
Specifiers: staticUFUNCTIONBlueprintCallable
Description
Finds every actor whose collision overlaps the given world-space sphere. Filters can restrict results by Object Type and by actor class.
Caveats & Gotchas
- • Internally calls SphereOverlapComponents and maps hit components back to owning actors, so an actor with several overlapping components still appears only once in OutActors.
- • ObjectTypes are Object Types (Project Settings > Engine > Collision), not Trace Channels — a component whose collision response to that object type is set to Ignore is never returned even though it geometrically overlaps the sphere.
- • Returns false whenever OutActors ends up empty after ActorClassFilter is applied, so the bool alone can't distinguish 'nothing overlapped' from 'something overlapped but didn't match the class filter'.
Signature
static ENGINE_API bool SphereOverlapActors(const UObject* WorldContextObject, const FVector SpherePos, float SphereRadius, const TArray<TEnumAsByte<EObjectTypeQuery> > & ObjectTypes, UClass* ActorClassFilter, const TArray<AActor*>& ActorsToIgnore, TArray<class AActor*>& OutActors) Parameters
| Name | Type | Description | Default |
|---|---|---|---|
| WorldContextObject | const UObject* | Object used to resolve which UWorld to run the query in. | — |
| SpherePos | const FVector | Center of the sphere in world space. | — |
| SphereRadius | float | Radius of the sphere. | — |
| ObjectTypes | const TArray<TEnumAsByte<EObjectTypeQuery> >& | Object Types (Project Settings > Collision) to restrict the query to. | — |
| ActorClassFilter | UClass* | If set, only actors of this class or subclasses are returned. | — |
| ActorsToIgnore | const TArray<AActor*>& | Actors excluded from the results. | — |
| OutActors | TArray<AActor*>& | Returned array of overlapping actors. Unsorted. | — |
Return Type
bool Example
Find overlapping pawns in a radius C++
TArray<TEnumAsByte<EObjectTypeQuery>> ObjectTypes;
ObjectTypes.Add(UEngineTypes::ConvertToObjectType(ECC_Pawn));
TArray<AActor*> ActorsToIgnore;
ActorsToIgnore.Add(this);
TArray<AActor*> OverlappingActors;
UKismetSystemLibrary::SphereOverlapActors(this, GetActorLocation(), 500.f, ObjectTypes, APawn::StaticClass(), ActorsToIgnore, OverlappingActors); Tags
Version History
Introduced in: 4.0
| Version | Status | Notes |
|---|---|---|
| 5.6 | stable | — |
Feedback
Was this helpful?