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?

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.

4 Likes