What's the "Professional" way to Initialize Classes?

The Goal:
Make sure that all classes are initialized and ready to be used on startup of a new map.

Personal Idea for Class Initialization:
Based on a Reddit Post, the order of class init seems to be:
Game Instance > Game Mode > Game State > Other…

Use the Game State class (normally i would use the Game Mode but I’m working on a multiplayer game and clients don’t have it). Define a bunch of bools for each class inside the Game State to detect if a selected class has been initialized (e.g. “IsHudInit?”). Finally I would cast to the Game State from each class on BeginPlay and set the bool for the selected class variable to true. When all init variables are true, the game would start.

Recommended Method by YouTuber Kekdot:

Show Video

https://youtu.be/7Gg4al46Kis

How would you do this professionally?
There might be ways to do init with C++ but I’m only interested in Blueprint based solutions, since I lack the experience. Any better suggestions than what I mentioned above are much appreciated!

Look into “game subsystem” (those are singletons with wrong name, but somebody at epic has singleton -phobia, i bet on some manager). You can pick what subsystem you piggy back (or make your own), and all init will be contained in your own class.

As to lack of C++ experience, it is quite easy (for simple things like creating own class with some events), also you can always ask some deep ai bots for help (however, this is 50/50 they provide a lot of buggy feedback), i personally use them as rubber duck and to gather proper keywords. Like that game subsystem thingy because somebody named singletons in unreal this way.

back to Your problem:

  • make event “Real_Begin"play” in game instance
  • make function that counts all things that are ready. I use for it game tags, for eg. init.hud, init.my_actor etc.
  • now it is matter of adding new game tag under this branch to add new item on the list
  • then any class that is ready sends info to game instance that its game tag is set.
  • game instance waits until all game tags in branch init. are set
  • then it fires “real begin play”

imo. game tags are more fancy enums, also unlike enums you can get name as string for them during runtime, which helps logging and debugging. So you can add print to log for each game tag.init set.

1 Like

Subsystem is the correct name as these are not singletons. They extend the existing classes and share their lifetime where a singleton would create itself if it doesn’t already exist.

2 Likes