ULocalPlayer

Each player that is active on the current client has a LocalPlayer.

Choose your operating system:

Windows

macOS

Linux

Inheritance Hierarchy

References

Module

Engine

Header

/Engine/Source/Runtime/Engine/Classes/Engine/LocalPlayer.h

Include

#include "Engine/LocalPlayer.h"

Syntax

class ULocalPlayer : public UPlayer

Remarks

Each player that is active on the current client has a LocalPlayer. It stays active across maps There may be several spawned in the case of splitscreen/coop. There may be 0 spawned on servers.

Variables

Name Description

Public variable

TEnumAsByte< en...

 

AspectRatioAxisConstraint

How to constrain perspective viewport FOV

Public variable

uint32: 1

 

bSentSplitJoin

Set when we've sent a split join request

Public variable

FUniqueNetIdRep...

 

CachedUniqueNetId

The FUniqueNetId which this player is associated with.

Public variable

FVector

 

LastViewLocation

The location of the player's view the previous frame.

Public variable

FVector2D

 

Origin

The coordinates for the upper left corner of the master viewport subregion allocated to this player.

Public variable

TSubclassOf< cl...

 

PendingLevelPlayerControllerClass

The class of PlayerController to spawn for players logging in.

Public variable

FVector2D

 

Size

The size of the master viewport subregion allocated to this player. 0-1

Protected variable

FReply

 

SlateOperations

FReply used to defer some slate operations.

Public variable

TObjectPtr< cla...

 

ViewportClient

The master viewport containing this player's view.

Constructors

Name Description

Public function

ULocalPlayer

(
    const FObjectInitializer& ObjectIn...
)

Public function

ULocalPlayer

(
    FVTableHelper& Helper
)

DO NOT USE. This constructor is for internal usage only for hot-reload purposes.

Functions

Name Description

Public function Static

void

 

AddReferencedObjects

(
    UObject* InThis,
    FReferenceCollector& Collector
)

Public function Virtual

FSceneView &...

 

CalcSceneView

(
    FSceneViewFamily* ViewFamily,
    FVector& OutViewLocation,
    FRotator& OutViewRotation,
    FViewport* Viewport,
    FViewElementDrawer* ViewDrawer,
    int32 StereoViewIndex
)

Calculate the view settings for drawing from this view actor

Public function Virtual

bool

 

CalcSceneViewInitOptions

(
    FSceneViewInitOptions& OutInitOpti...,
    FViewport* Viewport,
    FViewElementDrawer* ViewDrawer,
    int32 StereoViewIndex
)

Calculate the view init settings for drawing from this view actor

Public function Virtual

void

 

CleanupViewState()

Clear cached view state.

Protected function

void

 

ExecMacro

(
    const TCHAR* Filename,
    FOutputDevice& Ar
)

Public function Const

FUniqueNetId...

 

GetCachedUniqueNetId()

Retrieves this player's unique net ID that was previously cached

Public function Const

int32

 

GetControllerId()

Returns the physical controller ID for the player

Public function Const

UGameInstanc...

 

GetGameInstance()

Get the game instance associated with this local player

Public function Virtual Const

FString

 

GetGameLoginOptions()

Retrieves any game-specific login options for this player if this function returns a non-empty string, the returned option or options be added passed in to the level loading and connection code.

Public function Const

int32

 

GetIndexInGameInstance()

Returns the index of this player in the Game instances local players array

Public function Virtual Const

int32

 

GetLocalPlayerIndex()

Returns the logical local player index where 0 is the first player By default, this uses index in the game instance array

Public function Virtual Const

FString

 

GetNickname()

Retrieves this player's name/tag from the online subsystem if this function returns a non-empty string, the returned name will replace the "Name" URL parameter passed around in the level loading and connection code, which normally comes from DefaultEngine.ini

Public function Static

bool

 

GetPixelBoundingBox

(
    const FSceneViewProjectionData& Pr...,
    const FBox& ActorBox,
    FVector2D& OutLowerLeft,
    FVector2D& OutUpperRight,
    const FVector2D* OptionalAllot...
)

This function will give you two points in Pixel Space that surround the World Space box.

Public function

bool

 

GetPixelBoundingBox

(
    const FBox& ActorBox,
    FVector2D& OutLowerLeft,
    FVector2D& OutUpperRight,
    const FVector2D* OptionalAllot...
)

This function will give you two points in Pixel Space that surround the World Space box.

Public function

bool

 

GetPixelPoint

(
    const FVector& InPoint,
    FVector2D& OutPoint,
    const FVector2D* OptionalAllot...
)

This function will give you a point in Pixel Space from a World Space position

Public function Static

bool

 

GetPixelPoint

(
    const FSceneViewProjectionData& Pr...,
    const FVector& InPoint,
    FVector2D& OutPoint,
    const FVector2D* OptionalAllot...
)

This function will give you a point in Pixel Space from a World Space position

Public function Const

FPlatformUse...

 

GetPlatformUserId()

Returns the platform user that is assigned to this player

Public function Virtual Const

FUniqueNetId...

 

GetPreferredUniqueNetId()

Retrieves the preferred unique net id.

Public function Virtual Const

bool

 

GetProjectionData

(
    FViewport* Viewport,
    FSceneViewProjectionData& Projecti...,
    int32 StereoViewIndex
)

Helper function for deriving various bits of data needed for projection

Public function

FReply &

 

GetSlateOperations()

Getter for slate operations.

Public function Const

const FReply...

 

GetSlateOperations()

Public function Virtual

TSharedPtr< ...

 

GetSlateUser()

Get the SlateUser that this LocalPlayer corresponds to

Public function Virtual Const

TSharedPtr< ...

 

GetSlateUser()

Get the SlateUser that this LocalPlayer corresponds to

Public function Const

TSubsystemCl...

 

GetSubsystem()

Get a Subsystem of specified type

Public function Static

TSubsystemCl...

 

GetSubsystem

(
    const ULocalPlayer* LocalPlaye...
)

Get a Subsystem of specified type from the provided LocalPlayer returns nullptr if the Subsystem cannot be found or the LocalPlayer is null

Public function Const

const TArray...

 

GetSubsystemArray()

Get all Subsystem of specified type, this is only necessary for interfaces that can have multiple implementations instanced at a time.

Public function Const

ULocalPlayer...

 

GetSubsystemBase

Get a Subsystem of specified type

Public function Virtual Const

FUniqueNetId...

 

GetUniqueNetIdForPlatformUser()

Retrieves this player's unique net ID from the online subsystem using the platform user Id

Public function Const

FUniqueNetId...

 

GetUniqueNetIdFromCachedControllerId()

This should be deprecated when engine code has been changed to expect FPlatformUserId UE_DEPRECATED(5.x, "Use GetUniqueNetIdForPlatformUser instead")

Protected function Virtual Const

void

 

GetViewPoint

(
    FMinimalViewInfo& OutViewInfo
)

Retrieve the viewpoint of this player.

Public function Virtual Const

UWorld *

 

GetWorld()

Get the world the players actor belongs to

Public function

bool

 

HandleDNCommand

(
    const TCHAR* Cmd,
    FOutputDevice& Ar
)

Exec command handlers

Public function

bool

 

HandleExecCommand

(
    const TCHAR* Cmd,
    FOutputDevice& Ar
)

Public function

bool

 

HandleExitCommand

(
    const TCHAR* Cmd,
    FOutputDevice& Ar
)

Public function

bool

 

HandleListAwakeBodiesCommand

(
    const TCHAR* Cmd,
    FOutputDevice& Ar
)

Public function

bool

 

HandleListMoveBodyCommand

(
    const TCHAR* Cmd,
    FOutputDevice& Ar
)

Public function

bool

 

HandleListPawnComponentsCommand

(
    const TCHAR* Cmd,
    FOutputDevice& Ar
)

Public function

bool

 

HandleListSimBodiesCommand

(
    const TCHAR* Cmd,
    FOutputDevice& Ar
)

Public function

bool

 

HandleListSkelMeshesCommand

(
    const TCHAR* Cmd,
    FOutputDevice& Ar
)

Public function

bool

 

HandleMoveComponentTimesCommand

(
    const TCHAR* Cmd,
    FOutputDevice& Ar
)

Public function

bool

 

HandleToggleDrawEventsCommand

(
    const TCHAR* Cmd,
    FOutputDevice& Ar
)

Public function

bool

 

HandleToggleStreamingVolumesCommand

(
    const TCHAR* Cmd,
    FOutputDevice& Ar
)

Public function Virtual

void

 

InitOnlineSession()

Called to initialize the online delegates

Public function Const

bool

 

IsPrimaryPlayer()

Determines whether this player is the first and primary player on their machine.

Public function Const

FOnControlle...

 

OnControllerIdChanged()

Public function

FOnPlatformU...

 

OnPlatformUserIdChanged()

Public function Virtual

void

 

PlayerAdded

(
    UGameViewportClient* InViewpor...,
    int32 InControllerID
)

Called at creation time for internal setup

Public function Virtual

void

 

PlayerRemoved()

Called when the player is removed from the viewport client

Public function Virtual

void

 

SendSplitJoin

(
    TArray< FString >& Options
)

Send a splitscreen join command to the server to allow a splitscreen player to connect to the game the client must already be connected to a server for this function to work @note this happens automatically for all viewports that exist during the initial server connect so it's only necessary to manually call this for viewports created after that if the join fails (because the server was full, for example) all viewports on this client will be disconnected

Public function

void

 

SetCachedUniqueNetId

(
    FUniqueNetIdPtr NewUniqueNetId
)

Sets the players current cached unique net id

Public function Virtual

void

 

SetControllerId

(
    int32 NewControllerId
)

Change the physical ControllerId for this player; if the specified ControllerId is already taken by another player, changes the ControllerId for the other player to the ControllerId currently in use by this player.

Public function Virtual

void

 

SetPlatformUserId

(
    FPlatformUserId InPlatformUserId
)

Changes the platform user that is assigned to this player

Public function Virtual

bool

 

SpawnPlayActor

(
    const FString& URL,
    FString& OutError,
    UWorld* InWorld
)

Create an actor for this player.

Overridden from UObject

Name Description

Public function Virtual

void

 

FinishDestroy()

Called to finish destroying the object.

Public function Virtual

void

 

PostInitProperties()

Called after the C++ constructor and after the properties have been initialized, including those loaded from config.

Overridden from FExec

Name Description

Public function Virtual

bool

 

Exec

(
    UWorld* InWorld,
    const TCHAR* Cmd,
    FOutputDevice& Ar
)

Exec handler

Classes

Name

Description

Public class

FOnControllerIdChanged

Public class

FOnPlatformUserIdChanged

Event called when this local player has been assigned to a new platform-level user

Deprecated Functions

Name Description

Public function Const

bool

 

IsCachedUniqueNetIdPairedWithControllerId()

Platform User Id now has priority over ControllerId, these are not expected to be the same