GameplayStatics/Actor Functions/C++
Actor Functions GetActorArrayAverageLocation FVector GetActorArrayAverageLocation(const TArray<AActor*>& Actors) Find the average FVector location of an array of actors. Real world use ca...
Actor Functions
GetActorArrayAverageLocation
FVector GetActorArrayAverageLocation(const TArray<AActor*>& Actors)
Find the average FVector location of an array of actors.
Real world use case:
Perhaps you have a couch coop game, and want to position your spectator camera actor in the middle of all your players.
// Types
FVector CameraPositionVector;
TArray Players;
...
// Done only once at beginning of level (Expensive operation)
GetAllActorsOfClass(this, AMyPlayerCharacter::StaticClass(), Players);
...
// Done frequently (perhaps in tick)
CameraPositionVector = GetActorArrayAverageLocation(Players)
...
// Done as frequently as the position as changed.
SomeSpectatorCameraActor->SetActorLocation(CameraPosition);
GetActorArrayBounds
void GetActorArrayBounds(const TArray<AActor*>& Actors, bool bOnlyCollidingComponents, FVector& Center, FVector& BoxExtent);
TODO
GetActorOfClass
expensive operation
class AActor* GetActorOfClass(const UObject* WorldContextObject, TSubclassOf<AActor> ActorClass);
TODO
GetAllActorsOfClass
expensive operation
class AActor* GetActorOfClass(const UObject* WorldContextObject, TSubclassOf<AActor> ActorClass);
Useful for getting all actors of a class in the world.
Real world use case: Perhaps you want to upgrade all instances of your FootSoldier's health
// type
TArray FootSoldiers;
// Done once at upgrade completion
GetAllActorsOfClass(this, AMyFootSoldier::StaticClass(), FootSoldiers);
for (auto& FootSoldier : FootSoldiers) {
FootSoldier.UpgradeHealth();
}
GetAllActorsWithInterface
expensive operation
void GetAllActorsWithInterface(const UObject* WorldContextObject, TSubclassOf<UInterface> Interface, TArray<AActor*>& OutActors);
TODO
GetAllActorsWithTag
expensive operation
void GetAllActorsWithTag(const UObject* WorldContextObject, FName Tag, TArray<AActor*>& OutActors);
TODO
GetAllActorsOfClassWithTag
expensive operation
void GetAllActorsOfClassWithTag(const UObject* WorldContextObject, TSubclassOf<AActor> ActorClass, FName Tag, TArray<AActor*>& OutActors);
TODO