UGameplayStatics::CreatePlayer
#include "Kismet/GameplayStatics.h"
Access: public
Specifiers: staticUFUNCTIONBlueprintCallable
Description
Creates a new local player and optionally spawns a PlayerController for it, used for local multiplayer (split-screen) scenarios. Returns the new PlayerController, or null if creation failed.
Caveats & Gotchas
- • Calling this during Actor construction (BeginPlay has not yet fired) is unsafe — the meta tag UnsafeDuringActorConstruction will trigger a Blueprint warning, and in C++ the world may not be in a valid state.
- • When bSpawnPlayerController is false, the returned pointer is null; a controller is only spawned on the next seamless or hard travel. Accessing the return value in that case will crash.
- • Each call increments the local player count. Exceeding the maximum configured player count (set per-project) will silently fail and return null.
Signature
static ENGINE_API class APlayerController* CreatePlayer(const UObject* WorldContextObject, int32 ControllerId = -1, bool bSpawnPlayerController = true); Parameters
| Name | Type | Description | Default |
|---|---|---|---|
| WorldContextObject | const UObject* | Any object in the world to use as context. | — |
| ControllerId | int32 | The physical controller ID to assign. Pass -1 to use the next available ID. | -1 |
| bSpawnPlayerController | bool | Whether to immediately spawn a PlayerController. If false, one is created automatically on the next map transition. | true |
Return Type
APlayerController* Example
Add a second local player for split-screen C++
// In your GameMode or GameState
APlayerController* P2 = UGameplayStatics::CreatePlayer(this, 1, true);
if (P2)
{
// Optionally possess a pawn or open the character select UI
} See Also
Version History
Introduced in: 4.0
| Version | Status | Notes |
|---|---|---|
| 5.6 | stable | — |
Feedback
Was this helpful?