Advertisement
TheRedPixel

Faster Pawn Iteration

Apr 7th, 2025 (edited)
302
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.50 KB | Source Code | 0 0
  1. const FVector CursorPawnLocation = CursorPawn->GetActorLocation();
  2.  
  3. TArray<APawn*> GetPawnsInRange(const FVector ObservingLocation, const bool bShouldSortBySignificance) const
  4. {
  5.     UWorld* World = GetWorld();
  6.     TArray<APawn*> Results;
  7.     for (TActorIterator<APawn> It(World, APawn::StaticClass()); It; ++It)
  8.     {
  9.         APawn *Pawn = *It;
  10.         const float Distance = FVector::Distance(ObservingLocation, Pawn->GetActorLocation());
  11.         if (Distance <= GetColliderMaxRange())
  12.         {
  13.             Results.Add(Pawn);
  14.         }
  15.  }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement