반응형

UGameInstance

  • SHARE:

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.


https://docs.unrealengine.com/latest/INT/API/Runtime/Engine/Engine/UGameInstance/index.html





Thread: Game Instance VS Singleton

  1. #1
    0
    Infiltrator
    Join Date
    Jul 2014
    Posts
    14

    Game Instance VS Singleton

    The recently released UE 4.4 introduced the new UGameInstance class. From what I understand you can have a single global instance of UGameInstance per game and it stays even between level transitions. But I wonder: what are the main differences between a UGameInstance and a Singleton object (which was already available in earlier versions of UE4)? Do they have any advantages over one another or can do anything the other type can't? When should I use which type?
    Quick reply to this messageReply   Reply With QuoteReply With Quote   Multi-Quote This Message     
  2. #2
    0
    Unreal Engine Developer
    Join Date
    Mar 2014
    Posts
    294
    Frankly, GameSingleton was a bit of a hack put in by one of our game teams to deal with the fact that something like GameINstance didn't exist. I'd definitely recommend not using it going forward.

    In a standalone game the GameInstance and a Singleton (that is allocated at startup and cleaned up at shutdown) will have very similar lifespans, however, in the editor, GameInstance will exist just while a Play in Editor (PIE) session is running and there will be one for each PIE session. Game Singleton will exist for the entire duration of the editor and need to be cleaned up or managed each time you start or end a PIE session and if you are using the multiplayer PIE feature (where you can have multiple networked PIE windows within the editor) there is only one Singleton that is shared between them.


https://forums.unrealengine.com/showthread.php?29765-Game-Instance-VS-Singleton

반응형

+ Recent posts