There is no need to import the kismet library, just invoke what it does. and use SweepMultiByObjectType
. It’s pretty nice to dive through these methods and learn how these things work. Sometimes it is worth it or necessary to just import a thing from kismet, I don’t think that is the case here.
TArray<FHitResult> HitResults;
FVector Start = GetActorLocation(); // Center of the sphere
FVector End = Start; // No movement, just a sphere test
float Radius = 500.f; // Your sphere radius
FCollisionObjectQueryParams ObjectQueryParams;
ObjectQueryParams.AddObjectTypesToQuery(ECC_Pawn); // Example: looking for Pawns, add more as needed
ObjectQueryParams.AddObjectTypesToQuery(ECC_WorldDynamic);
FCollisionShape CollisionShape = FCollisionShape::MakeSphere(Radius);
bool bHit = GetWorld()->SweepMultiByObjectType(
HitResults,
Start,
End,
FQuat::Identity,
ObjectQueryParams,
CollisionShape
);
if (bHit)
{
for (const FHitResult& Hit : HitResults)
{
AActor* HitActor = Hit.GetActor();
if (HitActor)
{
UE_LOG(LogTemp, Warning, TEXT("Hit Actor: %s"), *HitActor->GetName());
}
}
}