For some reason I only got a notification on the Private Message but not here.
This has been already addressed in the PM/email, but I’ll respond here as well in case anybody else might have the same questions.
The issue in regards to the Player Pawn lies within the way Unreal handles spawning or possessing of pawns in general.
The engine will first look at the settings in the GameMode, i.e. what is set as the Default Pawn (e.g. First Person Character) or whether “Start Players As Spectators” is enabled.
This pawn will then be spawned at the PlayerStart, if (and only if) there are no pawns placed in the scene which are set to be possessed by the PlayerController (e.g. set “Auto Possess Player” to “Player 0”).
Next, each time a sublevel gets loaded which contains a pawn set up to be possessed (as above), the Engine will switch to that pawn (abandoning the previous one).
So, with level streaming the order of events we are aiming for would look like this:
- Game opens an empty level (the persistent one, which optimally should have no characters in it)
- Now the engine will look up in your GameMode what to do next, if there is a default pawn set, the character will get spawned (at PlayerStart or at 0,0,0 if none is present)
We don’t want to load a pawn at this point as the actual level hasn’t been loaded yet (the pawn might fall into the void).
To avoid that, enable “Start Players As Spectators” in the GameMode - which will just spawn a light weight floating pawn.
- Next the LSS Actor kicks in and loads the Loading Screen Scene - which will have its own pawn, that gets immediately possessed.
- In the background the actual game level gets loaded in.
- The instant the new level is set to visible, the engine will again look for any characters in the new level that have “Auto Possess Player” enabled
Note 1: if there are none, your camera would be left where the last pawn (from the Loading Screen scene) was located - you wouldn’t be able to move however, as that pawn has been deactivated or unloaded along the scene itself.
Note 2: The engine will not do anything with the GameMode settings at this point, no auto spawning at any PlayerStart, even if there is a new one in the fresh sublevel.
There are many ways you can handle your pawn here, the most simplistic is to place a pawn in each scene, including the Loading Screen scene, and set those to “Auto Possess Player”. That’s how the demo levels in the project handle it.
A different approach would be to use either BeginPlay of the sublevel or events from the LSS to spawn the pawn from blueprint (you could even querry the GameMode settings yourself and spawn the pawn at a PlayerStart if you wanted).
You could also spawn the character once, and using events teleport it around to appear in the newly loaded levels where you would need them (including in the loading screen scene itself if you wanted). For such a persistent pawn you would need:
- keep the reference to your current pawn (e.g. as a custom variable in game mode, player state or similar)
- hide the pawn (unless you would like to use the same pawn during the loading screen, which you could)
- go through the transition
- possess/show + teleport the pawn to a location in he newly loaded level
“1.” + “2.” you could bind to OnOpenLoadingScreen (event dispatcher of the LSS Actor) and “4.” to OnLoadingCompleted
Here you have some example code:
Screenshot: Imgur: The magic of the Internet
Pastebin: Begin Object Class=/Script/BlueprintGraph.K2Node_InputKey Name="K2Node_InputKey_ - Pastebin.com (paste into an empty level blueprint)
In this instance it’s placed in the level blueprint of the persistent level, so you could just drag in a reference to the pawn,
but it would work anywhere if the reference was saved globally (GameInstance, GameMode etc.).
The two events bound here in BeginPlay would fire on each transition (achieved in this example on keybindings), until unbound.
Keep in mind, that everything placed in the persistent level will increase the loading time before the loading screen can be shown, this probably wouldn’t be crucial with a single pawn, but it could be easily remedied by spawning the pawn during the first loading and save the reference globally.