Good/early place to instantiate an object

Hi,

I am trying to instantiate an object that is going to take care of any motion capture components for player controller.

So, if my game has menu before the actual game, it has to be instantiated before the actual game so GameMode or GameState would not be good place to instantiate this.

Where would be the best choice for this?

Hi Jae Yoo,

Have you had a look at GameInstance? It’s a good place to share variables between level blueprints, or how to easily have global, persistent variables that don’t go away when you change levels.

You can create a C++ class that inherets from GameInstance from the File menu by choosing “New C++ Class”. From there you can add any member variables you want, and override the Init() method and instantiate anything in there.

You can also create a Blueprint that inherets from GameInstance. You can add blueprint member variables and use the Event Init node to do any initialization necessary.

49695-gameinstancebp.png

Both Blueprint and C++ GameInstances can be set as the one to use for your project in the Project Settings > Maps & Modes screen:

Hope that helps!

Hi,

We think this post contains useful information which we would like to share with our public UE4 community. With your approval, we would like to make a copy of this post on the public AnswerHub which includes the discussion but strips out your username and company name. Please let us know if you are okay with this.

Thanks!

Please do.