So there is server travel. This means that while the level is loading, you have a little level which is like a loading screen. It loads the new level in the background before it switches you to the new level.
The player controller is persistent and stays loaded and doesnât restart when the next level pops up, so you need to get all your stuff set up for the new level after the new level loads. You can have a âRecastâ event on your controller which will reset any variables to start position. The game usually creates a new pawn so you will probably need to reset those variables too and get the new reference.
Some other things arenât persistent either. I donât have a persistent GameState for example but my GameMode is persistent. I donât have a persistent Hud either. Point being, anything that persists will have the references and stuff from the old level.
If you have the level wait like 0.1 seconds for any spawners to spawn objects into the level, and then have it get player 0 controller and then have it call the function âRecastâ then it will get the actor of class from the new level and the location etc.
The best way is to do the restart player in the game mode like you have but the thing is, you need the playerstart to be there before it can restart the player. Also you should have the new level get the GameMode, cast to the GameMode and then trigger LoadLevel, it will then do the restart and the character position will be restarted.
With the games, the controller is like the foreman telling all the workers what to do, and communicating with the boss of the factory. The character is like a worker, handling itâs own stuff based on what itâs told to do by the foreman. The boss of the factory is like the GameMode. It doesnât really talk to the workers but it can hard ball move workers in and instant. It handles where everyone starts and where they start their work. The Game State is like a secretary that has all the information about the state of the factory. Itâs a great place to handle all the scores and multicasts from the GameMode. Like the GameMode tells the GameState to tell everyone that something has happened. PlayerState is like a performance evaluator for the worker, just keeping and eye on all the information about the player. So you can store stuff there like What clothes the player is wearing etc. And if something needs to know about the player, it can access the Player State.
Point being, Youâre a controller, telling a character what to do in the factory level. The boss GameMode can talk to the controller but usually the GameMode boss gets the GameState to handle the operations of the factory. GameMode mainly handles the positioning of characters and overall running of the core of the game. Win Conditions, level transitions etc, based on what the GameState information.
I also have a HUD actor too which handles all my widget stuff. Controller just asks the Hud to create or destroy stuff and the Hud does all the work
So try to have each section do itâs own job. When you have 1 thing doing everything, it gets messy and you canât really debug well. If itâs a widget creation error, then where in the haystack of code would it be? With the HUD handling creation, you know exactly who to go to to deal with the problem.
Imagine a factory where everyone does every job for themselves. So they pay themselves and order their own gear and fix their own machines and other peoples machines. When something goes wrong, who do you talk to? Where do you go looking for the problem?
So if you can look at setting all that up in a similar way you will find the process gets much easier. And if you ever go to multiplayer, youâll be thankful you did.