UGameInstance

GameInstance: high-level manager object for an instance of the running game.

Windows
MacOS
Linux

Inheritance Hierarchy

References

Module

Engine

Header

/Engine/Source/Runtime/Engine/Classes/Engine/GameInstance.h

Include

#include "Engine/GameInstance.h"

Syntax

class UGameInstance :
    public UObject,
    public FExec

Remarks

GameInstance: high-level manager object for an instance of the running game. Spawned at game creation and not destroyed until game instance is shut down. Running as a standalone game, there will be one of these. Running in PIE (play-in-editor) will generate one of these per PIE instance.

Variables

Name Description

Public variable

FLatentActionMa...

 

LatentActionManager

Protected variable

TArray< ULocalP...

 

LocalPlayers

List of locally participating players in this game instance

Protected variable

FOnPreClientTra...

 

NotifyPreClientTravelDelegates

Listeners to PreClientTravel call

Protected variable

UOnlineSession ...

 

OnlineSession

Class to manage online services

Protected variable

FDelegateHandle

 

OnPlayTogetherEventReceivedDelegateHandle

Handle for delegate for handling PS4 play together system events

Public variable

FString

 

PIEMapName

Protected variable

TArray< UObject...

 

ReferencedObjects

List of objects that are being kept alive by this game instance.

Public variable

FTimerManager &...

 

TimerManager

Protected variable

FWorldContext &...

 

WorldContext

Constructors

Name Description

Public function

UGameInstance

(
    const FObjectInitializer& ObjectIn...
)

Functions

Name Description

Public function Virtual

int32

 

AddLocalPlayer

(
    ULocalPlayer* NewPlayer,
    int32 ControllerId
)

Adds a LocalPlayer to the local and global list of Players.

Public function Virtual

void

 

AddUserToReplay

(
    const FString& UserString
)

Adds a join-in-progress user to the set of users associated with the currently recording replay (if any)

Public function

void

 

CleanupGameViewport()

Public function Virtual

bool

 

ClientTravelToSession

(
    int32 ControllerId,
    FName InSessionName
)

Helper function for traveling to a session that has already been joined via the online platform Grabs the URL from the session info and travels

Public function Virtual

AGameModeBas...

 

CreateGameModeForURL

(
    FURL InURL
)

Call to create the game mode for a given map URL

Public function Virtual

ULocalPlayer...

 

CreateInitialPlayer

(
    FString& OutError
)

Public function

ULocalPlayer...

 

CreateLocalPlayer

(
    int32 ControllerId,
    FString& OutError,
    bool bSpawnPlayerController
)

Adds a new player.

Public function Static

void

 

CreateMinimalNetRPCWorld

(
    const FName InPackageName,
    UPackage*& OutWorldPackage,
    UWorld*& OutWorld
)

Static util function used by InitializeForMinimalNetRPC and LoadMap to create the minimal world suitable for basic network RPC

Public function Virtual

void

 

DebugCreatePlayer

(
    int32 ControllerId
)

Local player access Debug console command to create a player.

Public function Virtual

void

 

DebugRemovePlayer

(
    int32 ControllerId
)

Debug console command to remove the player with a given controller ID.

Public function Virtual

bool

 

DelayPendingNetGameTravel()

Return true to delay an otherwise ready-to-join PendingNetGame performing LoadMap() and finishing up useful to wait for content downloads, etc

Public function Const

ULocalPlayer...

 

FindLocalPlayerFromControllerId

(
    const int32 ControllerId
)

Public function Const

ULocalPlayer...

 

FindLocalPlayerFromUniqueNetId

(
    const FUniqueNetId& UniqueNetId
)

Public function Const

ULocalPlayer...

 

FindLocalPlayerFromUniqueNetId

(
    TSharedPtr< const FUniqueNetId > Un...
)

Public function Const

UEngine *...

 

GetEngine()

Public function Const

ULocalPlayer...

 

GetFirstGamePlayer()

Public function Const

APlayerContr...

 

GetFirstLocalPlayerController

(
    UWorld* World
)

Public function Const

UGameViewpor...

 

GetGameViewportClient()

Public function Const

FLatentActio...

 

GetLatentActionManager()

Public function Const

ULocalPlayer...

 

GetLocalPlayerByIndex

(
    const int32 Index
)

Public function Const

TArray< ULoc...

 

GetLocalPlayerIterator()

Public function Const

const TArray...

 

GetLocalPlayers()

Public function Const

int32

 

GetNumLocalPlayers()

Public function Virtual Const

FName

 

GetOnlinePlatformName()

Retrieves the name of the online subsystem for the platform used by this instance.

Public function Const

UOnlineSessi...

 

GetOnlineSession()

Public function Virtual

TSubclassOf<...

 

GetOnlineSessionClass()

Public function Const

APlayerContr...

 

GetPrimaryPlayerController()

Get the primary player controller on this machine (others are splitscreen children) (must have valid player state and unique id)

Public function Const

TSharedPtr< ...

 

GetPrimaryPlayerUniqueId()

Get the unique id for the primary player on this machine (others are splitscreen children)

Public function Const

TSubsystemCl...

 

GetSubsystem()

Get a Subsystem of specified type

Public function Static

TSubsystemCl...

 

GetSubsystem

(
    const UGameInstance* GameInsta...
)

Get a Subsystem of specified type from the provided GameInstance returns nullptr if the Subsystem cannot be found or the GameInstance 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

UGameInstanc...

 

GetSubsystemBase

Get a Subsystem of specified type

Public function Const

FTimerManage...

 

GetTimerManager()

Public function Virtual Const

UWorld *

 

GetWorld()

Public function Const

FWorldContex...

 

GetWorldContext()

Public function Virtual

void

 

HandleDemoPlaybackFailure

(
    EDemoPlayFailure::Type FailureType,
    const FString& ErrorString
)

Called when demo playback fails for any reason

Protected function Virtual

bool

 

HandleDisconnectCommand

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

Public function Virtual

void

 

HandleGameNetControlMessage

(
    UNetConnection* Connection,
    uint8 MessageByte,
    const FString& MessageStr
)

Handle a game specific net control message (NMT_GameSpecific) this allows games to insert their own logic into the control channel the meaning of both data parameters is game-specific

Public function

void

 

HandleNetworkError

(
    ENetworkFailure::Type FailureType,
    bool bIsServer
)

Opportunity for blueprints to handle network errors.

Protected function Virtual

bool

 

HandleOpenCommand

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

Protected function Virtual

bool

 

HandleReconnectCommand

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

Protected function Virtual

bool

 

HandleTravelCommand

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

Public function

void

 

HandleTravelError

(
    ETravelFailure::Type FailureType
)

Opportunity for blueprints to handle travel errors.

Public function Virtual

void

 

Init()

Virtual function to allow custom GameInstances an opportunity to set up what it needs

Public function

void

 

InitializeForMinimalNetRPC

(
    const FName InPackageName
)

Called to initialize the game instance with a minimal world suitable for basic network RPC

Public function Virtual

FGameInstanc...

 

InitializeForPlayInEditor

(
    int32 PIEInstanceIndex,
    const FGameInstancePIEParameters& ...
)

Called to initialize the game instance for PIE instances of the game

Public function

void

 

InitializeStandalone()

Called to initialize the game instance for standalone instances of the game

Public function Const

bool

 

IsDedicatedServerInstance()

Returns true if this instance is for a dedicated server world

Public function Virtual

bool

 

JoinSession

(
    ULocalPlayer* LocalPlayer,
    int32 SessionIndexInSearchResults
)

Public function Virtual

bool

 

JoinSession

(
    ULocalPlayer* LocalPlayer,
    const FOnlineSessionSearchResult& ...
)

Public function Virtual

void

 

LoadComplete

(
    const float LoadTime,
    const FString& MapName
)

Public function

void

 

NotifyPreClientTravel

(
    const FString& PendingURL,
    ETravelType TravelType,
    bool bIsSeamlessTravel
)

Broadcast a notification that travel is occurring

Protected function

void

 

OnConsoleInput

(
    const FString& Command
)

Delegate for handling external console commands

Public function

FOnPreClient...

 

OnNotifyPreClientTravel()

Protected function

void

 

OnPlayTogetherEventReceived

(
    int32 UserIndex,
    const TArray< const FUniqueNetId& ...
)

Delegate for handling PS4 play together system events

Public function Virtual

void

 

OnSeamlessTravelDuringReplay()

This gets called when the player scrubs in a replay to a different level

Protected function Virtual

void

 

OnStart()

Called when the game instance is started either normally or through PIE.

Public function Virtual Const

TSubclassOf<...

 

OverrideGameModeClass

(
    TSubclassOf< AGameModeBase > GameMo...,
    const FString& MapName,
    const FString& Options,
    const FString& Portal
)

Return the game mode subclass to use for a given map, options, and portal.

Public function Virtual

bool

 

PlayReplay

(
    const FString& InName,
    UWorld* WorldOverride,
    const TArray< FString >& Additiona...
)

Start playing back a previously recorded replay. Return false if it fails to play.

Public function Virtual

FGameInstanc...

 

PostCreateGameModeForPIE

(
    const FGameInstancePIEParameters& ...,
    AGameModeBase* GameMode
)

Called as soon as the game mode is spawned, to allow additional PIE setting validation prior to creating the local players / etc...

Public function Virtual

void

 

PreloadContentForURL

(
    FURL InURL
)

Call to preload any content before loading a map URL, used during seamless travel as well as map loading

Public function Virtual

void

 

ReceivedNetworkEncryptionAck

(
    const FOnEncryptionKeyResponse& De...
)

Called when a client receives the EncryptionAck control message from the server, will generally enable encryption.

Public function Virtual

void

 

ReceivedNetworkEncryptionToken

(
    const FString& EncryptionToken,
    const FOnEncryptionKeyResponse& De...
)

Handle setting up encryption keys.

Public function

void

 

ReceiveInit()

Opportunity for blueprints to handle the game instance being initialized.

Public function

void

 

ReceiveShutdown()

Opportunity for blueprints to handle the game instance being shutdown.

Public function Virtual

void

 

RegisterReferencedObject

(
    UObject* ObjectToReference
)

Registers an object to keep alive as long as this game instance is alive

Public function

bool

 

RemoveLocalPlayer

(
    ULocalPlayer* ExistingPlayer
)

Removes a player.

Public function Virtual

void

 

ReturnToMainMenu()

Calls HandleDisconnect on either the OnlineSession if it exists or the engine, to cause a travel back to the default map.

Public function Virtual

void

 

Shutdown()

Virtual function to allow custom GameInstances an opportunity to do cleanup when shutting down

Public function Virtual

void

 

StartGameInstance()

Starts the GameInstance state machine running

Public function Virtual

FGameInstanc...

 

StartPlayInEditorGameInstance

(
    ULocalPlayer* LocalPlayer,
    const FGameInstancePIEParameters& ...
)

Called to actually start the game when doing Play/Simulate In Editor

Public function Virtual

void

 

StartRecordingReplay

(
    const FString& InName,
    const FString& FriendlyName,
    const TArray< FString >& Additiona...
)

Start recording a replay with the given custom name and friendly name.

Public function Virtual

void

 

StopRecordingReplay()

Stop recording a replay if one is currently in progress

Public function Virtual

void

 

UnregisterReferencedObject

(
    UObject* ObjectToReference
)

Remove a referenced object, this will allow it to GC out

Overridden from UObject

Name Description

Public function Virtual

void

 

FinishDestroy()

Called to finish destroying the object.

Overridden from FExec

Name Description

Public function Virtual

bool

 

Exec

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

Exec handler

Deprecated Functions

Name Description

Public function Virtual

bool

 

InitializePIE

(
    bool bAnyBlueprintErrors,
    int32 PIEInstance,
    bool bRunAsDedicated
)

Please override InitializeForPIE instead

Public function Virtual

bool

 

StartPIEGameInstance

(
    ULocalPlayer* LocalPlayer,
    bool bInSimulateInEditor,
    bool bAnyBlueprintErrors,
    bool bStartInSpectatorMode
)

Please override StartPlayInEditorGameInstance instead

Select Skin
Light
Dark

Welcome to the new Unreal Engine 4 Documentation site!

We're working on lots of new features including a feedback system so you can tell us how we are doing. It's not quite ready for use in the wild yet, so head over to the Documentation Feedback forum to tell us about this page or call out any issues you are encountering in the meantime.

We'll be sure to let you know when the new system is up and running.

Post Feedback