Why use GameInstance::Init()?

Init() in GameInstance is something like BeginPlay in Actors.

In UE4 no matter if this is UObject or AActor you can use constructors safely only for initializing variables or doing things that must be done explicitly in constructors (like creating components in actors).

Creating objects, spawning objects, filling arrays with objects etc. are concidered unsafe in constructors and must be done via Init(), BeginPlay() or other function designed for it.

UE4 uses heavily modified C++ with its own set of rules. Constructors are not always called when spawning objects as they use CDO, which is something like master object used for cloning other objects.

Lets just say - the best practice is to use UE4 functions as they meant to be used to avoid future problems :smiley:

4 Likes