I’ve been having some trouble. I know the basic way of changing the level but what if I want there to be more then one entrance like a cave or a huge open world and want the player to spawn outside of the house or cave’s entrance? I tried the teleport command in the Blueprint but it just keeps taking me to location ‘0.0.0’ anyways. Is there a way to make it to where the player will spawn at a certain actor or just a certain location on that level?
The simplest way to handle this is to spawn the player somewhere offscreen, in the dark, or while a UI is covering the screen (Loading…). Then pick where you want them and move the player there with either teleport or set location.
Be certain the location you are moving to is valid though. If you try to move somewhere and it encroaches the player it can destroy the actor and your camera will just go to 0, 0, 0. Try setting the locations you are teleporting to either higher up (some games you may notice you spawn and fall a little) or by finding the spawn position, adding some Z to it and tracing down to the ground with a sphere trace the radius of the pawn. This will hopefully guarantee a starting location.
I know this post is a bit old, but I wanted to expand on that answer. You can use a Game Instance to achieve this. Basically when the player collides with the trigger volume, door, static mesh, etc (whatever you have triggering the level change), it should first set a variable. So if you want your player to move to Level: Dark Forest at Entry Point: 2, assuming you’ve got multiple possible entry points, then set EntryPoint=2. It’s probably best to create an enum for this. Then pass that value to the Game Instance. When you load the Dark Forest, do a switch on the enum to check the value and move the player to the corresponding point.
To Recap:
- Create a Game Instance - this persists as long as the game is running.
- Create an Enum containing possible spawn points for a level (or all levels), or create multiple Enums - one for each level.
- In your player, when they collide with the level changing trigger, have them set the Enum value and pass it to the Game Instance.
- When the new level loads, load the Enum value from the game instance, run a switch on it, and move the player to the corresponding spawn point. It would be good to check if it’s valid first so you don’t spawn the player underground or in a wall.
- That’s it!
Wanted to leave this here in case anyone else comes looking for an answer and wanted more information. Sorry to necro an old post.