UGameplayStatics::GetPlayerController
#include "Kismet/GameplayStatics.h"
Access: public
Specifiers: static
Description
Returns the APlayerController for the given local player index, or null if no controller exists at that index.
Signature
static ENGINE_API APlayerController* GetPlayerController(const UObject* WorldContextObject, int32 PlayerIndex) Parameters
| Name | Type | Description | Default |
|---|---|---|---|
| WorldContextObject | const UObject* | Any valid UObject in the world. | — |
| PlayerIndex | int32 | Zero-based local player index. Use 0 for single-player. | — |
Return Type
APlayerController* Caveats & Gotchas
- • In C++ from an Actor context, GetWorld()->GetFirstPlayerController() is faster and more direct for single-player.
- • On a dedicated server, local player controllers don't exist — this will return null. Use PlayerIndex only for split-screen local multiplayer.
- • Returns null if PlayerIndex is out of range or the controller hasn't been created yet (e.g. called too early in initialisation).
Example
Get controller and show mouse cursor C++
APlayerController* PC = UGameplayStatics::GetPlayerController(this, 0);
if (IsValid(PC))
{
PC->SetShowMouseCursor(true);
PC->SetInputMode(FInputModeUIOnly());
} Tags
Version History
Introduced in: unknown
| Version | Status | Notes |
|---|---|---|
| 5.6 | stable | — |
Feedback
Was this helpful?