GameplayStatics/Player Functions
Deprecated Introduction Gameplay statics covering Player related functions Player Functions GetGameInstance class UGameInstance* GetGameInstance(const UObject* WorldContextObject); The GameInstance...
Deprecated
Introduction
Gameplay statics covering Player related functions
Player Functions
GetGameInstance
class UGameInstance* GetGameInstance(const UObject* WorldContextObject);
The GameInstance persists throughout the lifetime of the game, even traveling between maps.
Note: That a GameInstance doesn't get instantiated in the editor until you hit Play.
Common usage
UGameInstance* gameInstance = UGameplayStatics::GetGameInstance(someWorldContextObject);
In addition to GameplayStatics, this function is also available through Actors and World.
UGameInstance* gameInstance = GetWorld()->GetGameInstance();
if (UMyGameInstance* myGameInstance = Cast(gameInstance)) {
...
UGameInstance* gameInstance = GetWorld()->GetGameInstance();
void USomething::Example() {
UGameInstance* gameInstance = GetWorld()->GetGameInstance();
}
AActor* SomeActor;
...
UGameInstance* gameInstance = SomeActor->GetGameInstance();
GetPlayerController
class APlayerController* GetPlayerController(const UObject* WorldContextObject, int32 PlayerIndex);
GetPlayerController
APlayerController* playerController = UGameplayStatics::GetPlayerController(this, 0);
GetPlayerControllerFromID
class APlayerController* GetPlayerControllerFromID(const UObject* WorldContextObject, int32 ControllerID);
GetPlayerPawn
class APawn* GetPlayerPawn(const UObject* WorldContextObject, int32 PlayerIndex);
GetPlayerCharacter
class ACharacter* GetPlayerCharacter(const UObject* WorldContextObject, int32 PlayerIndex);
GetPlayerCameraManager
class APlayerCameraManager* GetPlayerCameraManager(const UObject* WorldContextObject, int32 PlayerIndex);
CreatePlayer
class APlayerController* CreatePlayer(const UObject* WorldContextObject, int32 ControllerId = -1, bool bSpawnPlayerController = true);
RemovePlayer
void RemovePlayer(APlayerController* Player, bool bDestroyPawn);
GetPlayerControllerID
int32 GetPlayerControllerID(APlayerController* Player);
SetPlayerControllerID
void SetPlayerControllerID(APlayerController* Player, int32 ControllerId);