RealDocs

UGameplayStatics::GetNumLocalPlayerControllers

function Engine Blueprint Since 5.1
#include "Kismet/GameplayStatics.h"
Access: public Specifiers: staticBlueprintPure

Description

Returns the count of fully initialized local player controllers. Returns 0 on dedicated servers. Indices 0 through this value minus one are guaranteed to be local players.

Caveats & Gotchas

  • Returns 0 on dedicated servers since there are no local players — use this to gate local-player-specific logic rather than hardcoding an assumption about the number of local players.
  • A local player controller is 'fully initialized' — players in the process of being created (e.g. during CreatePlayer) may not be counted until the next frame.
  • For split-screen games, this returns the number of active split-screen players, which can change at runtime as players join or leave local multiplayer sessions.

Signature

static ENGINE_API int32 GetNumLocalPlayerControllers(const UObject* WorldContextObject);

Parameters

Name Type Description Default
WorldContextObject const UObject* Object used to retrieve the world context.

Return Type

int32

Example

Apply local post-process effects to all local players C++
int32 NumLocal = UGameplayStatics::GetNumLocalPlayerControllers(this);
for (int32 i = 0; i < NumLocal; ++i)
{
    APlayerController* PC = UGameplayStatics::GetPlayerController(this, i);
    if (PC) PC->PlayerCameraManager->AddNewCameraModifier(UMyBloomModifier::StaticClass());
}

Version History

Introduced in: 5.1

Version Status Notes
5.6 stable

Feedback

Was this helpful?

Suggest an edit

Select a field above to begin editing.