How to properly Load a Game

Hello guys!
Today I am working on the loading system.

Basically, what I have now is: the GameInstance calls BeginLoadingScreen & LoadGame, then, it informs the GameMode that everything is ready and proceeds to settingup the controller and the character.

But how do I make sure that the Character gets spawned only when the map and the GUI are fully loaded?

You load a scene, inside the scene the game mode does all that for you. You don’t have to communicate with game mode

1 Like

Yes this works in theory. But then you have 3d widget on actor that spawns from some script in game mode (that is run after begin play). Then all references to this 3d widget on actor will not work.

So in case simple begin play in game mode fails:

  • use either struct with boolean values for each system, or gameplay tags can work as better/fancy enums that have bool values.
  • set them to true (as system is ready)
  • in game instance check if all bool are set.
  • if so fire up “real” begin play.
1 Like

Normally I do it the other way around, if the Gamemode or any actor needs a reference, it is the object that is spanned that calls the gamemode with an event to register. I always like to use Begin play as little as possible.

1 Like

Thank you @DomusLudus & @Nawrot
I am trying to use as little Begin Play as possible, and the moment the flow is:

GameInstance calls Loading Screen → When everything is loaded it signals the GameMode that everything is loaded and ready to use → GameMode spawns Controller & Character when I need it.

But a friend was asking if this would still work if, at some point, some stuff has yet to be spawned and the character and controller spawn before it and the player starts pressing keys while the scene is not ready yet?

I don’t think this might happen, but I don’t really know. I am new to UE.

1 Like

It should work. Also using begin play is safe for things that do not reference other actors.

And quite important: package your game, run it without editor loaded. In editor, then standalone and in packaged game, things sometimes are loaded and started in different order.

1 Like

But just to be sure that the Player won’t be able to use the controller untill the whole level is loaded, could I check in the GameMode if the Level is Loaded and only then make the controller possess the pawn?

On open world maps where you have streaming, it is really hard to determine if everything is loaded in. Even Epics Fortnite has trouble with it.

So it would give me only and approximation?

No you can get it with async load of a level.

My point is that even with it, and code done by epic people, Fortnite sometimes still streaming when i join game.

So that whole loading and streaming in is not that simple.

Oh and on top of that, when you use open level and streaming, game unloads certain actors. When they are loaded back their state is reset to default like they just spawned (because they did just that).

1 Like

Oohh, I see! Thank you for your in depth reply.

There are many things that happen that you can control from the “Game mode” blueprint that go in the following order:
The first is ChoosePlayerStart, which you can where you choose where to spawn the player.
Then there is “OnPostLogin” that is only activated if the player is loaded and has a controller
and finally there is the “BeginPlay”

Then in the controller “BeginPlay” is activated and then the “OnLoggin” has called when the controller posses it and finally in the character its “BeginPlay”

As a note when you spawn an object and call a function immediately this function is activated before the begin play of the object
There are also the constructors that are called before any begin play

I don’t know if there may be massive multiplayer maps that cause problems, but the player does not have input actives while the controller having been loaded first and possed.
Also, what inputs do you use? because with the enhanced input having the events in the player itself it is already impossible