Where to put game initialization logic?

Hello, I’m making a Trading Card Game and I am a little confused as to where to put the game initialization logic.
by game initialization I mean all the stuff that are general for the game like spawning some initial actors, setting up initial cameras, etc.

For example in my game a normal match has 1 player and 1 AI controlled pawn, a field, two decks belonging to each player, etc…
I wanted to know if for example to spawn the field and cards should i put that logic inside the player controller or in the GameMode or create a class that handles all that and put it in the level as an actor?

You can put that in Gamemode and load anything you want from there. You can have multiple gamemode to handle different thing like MainMenu Gamemode : show your main screen with menu, login … Normal Gamemode: 1 player vs 1 Ai like you said, then maybe Multiplayer Gamemode,

When you want to test it also very easy to test, just change Gamemode in World setting of your level you can test any specific mode you want.

1 Like

I think a good place to put the initailization logic in this case would be at Level Blueprint with BeginPlay event. This way game data will be driven by level blueprint to keep game mode and player controller independent.

Thanks i was confused as to how to use the GameMode, now i kinda understand it.

This comes up as a top answer on Google search, if I could downvote it would. Game mode is not good as the order of priority cannot be guaranteed. So your player/level can start performing actions before the Game mode has initialized.

Yes it’s true, but in term of initialization a gameplay logic, Gamemode is a good place to start and it’s reusable across levels.
This answer was to solve his particular issue though.

Just becareful is all, GameMode will not initialise before PlayerController if your character is placed in the world. If you spawn it from GameMode sure, but spawn it any other way then PlayerController will initialise before GameMode (this is not the order in Editor, but it is in Packaged, inconsistent or maybe a bug in UE4, but easy to trip up on)