Download

Lock On / Target Switching lags on detailed map.

I have tested this with many actors on blank map and its pretty fast (No Lag noticable) even with 50 actors. This is slow even with 1+ actors that you can lock on. I am not sure why. I set EFluidCameraLiteFrustrumMode to None in testing so I am not using that part of code. I set Collision mode to “ECC_Pawn” so it should not be hitting any of my environment.
Everything works, I just need help speeding this up.

It is this Function Slowing Things Down




TArray<AActor*> UFluidCameraLiteBPLibrary::HelperGetActorAtTrace(AActor* Actor, TArray<AActor*> Actors, ECollisionChannel CollisionChannel, float MaxDistance)
{
//Data
auto R = TArray<AActor*>();


if (Actor == nullptr)
return R;

TArray<AActor*> HitActors;
TArray<FHitResult> HitResults;
FVector StartLocation = Actor->GetActorLocation();
FVector EndLocation = StartLocation;
FCollisionShape CollisionShape = FCollisionShape::MakeSphere(MaxDistance);

//Do HIt
bool isHit = Actor->GetWorld()->SweepMultiByChannel(HitResults, StartLocation, EndLocation, FQuat::Identity, CollisionChannel, CollisionShape);

//IF Not Hit
if (!isHit)
return TArray<AActor*>();

for (auto& Hit : HitResults)
if (Actors.Contains(Hit.GetActor()) && Hit.GetActor() != Actor)
{
HitActors.Add(Hit.GetActor());
}
return HitActors;
}