UE4版本:4.26
由于没能在网上找到,有多对象的球体查询 SphereTraceMultiForObjects 的C++使用案例,所以我这里打算记录一下。
float SeekRadius;
TArray<FHitResult> HitResults;
FVector BeginLocation = ControlledPawn->GetActorLocation();
FVector EndLocation = BeginLocation + ControlledPawn->GetActorForwardVector() * 1;
TArray<TEnumAsByte<EObjectTypeQuery>> ObjectTypes;
ObjectTypes.Add(EObjectTypeQuery::ObjectTypeQuery2);//Pawn
TArray<AActor* > IgnoreActors;
bool bIsHit = UKismetSystemLibrary::SphereTraceMultiForObjects(GetWorld(), BeginLocation, EndLocation, SeekRadius, ObjectTypes, false, IgnoreActors, EDrawDebugTrace::ForDuration, HitResults, true);
if (bIsHit)
{
for (FHitResult HitResult : HitResults)
{
if (HitResult.Actor != NULL)
{
//对Actor们做的事情
}
}
}