I am trying to find all actors of a Worker class I created derived from ACharacter within a certain radius using the following code:
TArray<struct FOverlapResult> Overlaps;
if (World->OverlapMultiByObjectType(Overlaps, GetWorldLocationOfCubeCenter(CubeToRemove),
FQuat::Identity, FCollisionObjectQueryParams(ECC_Pawn), FCollisionShape::MakeSphere(10000.0f), FCollisionQueryParams()))
for (auto& Object : Overlaps)
// do stuff
In the blueprint for the Worker class, I have “Generate Overlap Events” selected under “Capsule Component.” I have tried using a collision preset on the worker of Pawn, and have also tried using a custom collision profile in which overlap is selected for all collision responses, but World->OverlapMultiByObjectType always returns false. I would appreciate any suggestions on what I might be doing wrong.
Still haven’t solved this. Any ideas welcome.
There’s only two possibilities:
- You don’t have the data properly setup (Make sure Generate Overlap Events is turned on for BOTH actors - if one has it on and one has it off, the system ignores it).
- Your query is located in some odd place and thus not hitting anything.
See Collision Overview | Unreal Engine Documentation
A third option is to skip the query entirely and just use an Actor iterator and a simple distance check.
const float distanceSquared = 10000.0f * 10000.0f
const FVector CenterCube = GetWorldLocationOfCubeCenter(CubeToRemove);
for (AActor* Worker : TActorRange<AActor>(GetWorld(), WorkerClass))
if (FVector::DistSquared(CenterCube, Worker->GetActorLocation) < distanceSquared)
// Do stuff.
What do you mean BOTH actors? With this function I’d expect to have the specified shape to be checked against all actors that correspond to the given parameters. Which is the second actor on which to activate the Overlap Events?
Also a connected question: does this call use the Actors’ collision shapes? Is there an equivalent method using simply the actors’ Bounding Sphere or Box?