Hi there, this question has been asked before but I couldn’t apply it to my situation or it was answered in C++.
I’m simply trying to change where my player spawns from level to level. Lets say I have location 1 somewhere on level 1. I spawn here when I start the game but there is a house (level 2 - a different map) once I have spawned in level 2 I might feel like leaving so I go back to level 1, only thing is that I want to spawn at Location 2 not location 1 of level 1.
Same thing could be applied to having a village with multiple house levels. I enter house 1 and leave, so I spawn outside the house 1 door. Enter house 2 and leaving I should spawn outside house 2. the same with house 3, 4, 5 etc. It is a single player game in blueprints.
Be gentle I’m not a pro. If you need screenshots to further explain I’d be happy to provide. Be as detailed as possible in your answer if possible for greater chance of me and any others understanding.
You need to use savegame. for example, you need to save your latest location in variable called “Level 1 latest Loc” before going to level 2. Now when you want to comeback to level 1, in beginplay teleport player to that location from “Level 1 latest Loc”.
Of course there are multiple ways you can achieve this; like checkpoint system that automatically save player location and then respawn player to that location.
Hey there, there are a few ways of doing this but you can something like this:
On each level you place 2 player starts, one for the beginning and another for the next level.
On the beginning player start you edit the instance and set the Player Start Tag to 0
On the next level player start you edit the instance and set the Player Start Tag to 2
Next you store in your game instance or in a save file the last level you were on (set right before you call Open Level)
Create a custom Game Mode and override the function Choose Player Start, this will return the player start you will spawn your player when the level begins. The only thing you need to do now is do a Get All actors of class for the type Player Start. This will give you all the player starts in the level. You do a for loop on that and the one that is going to be picked is the one with the same value on the Player Start Tag. So if you are going from level 2 to level 1, the variable would be 2, so that means we would pick the player start with Player Start Tag of 2.
Can you elaborate on the save part of things. I’ve used game instances before but never had to save anything other than health How would I go about saving the last level I was on?
Also do I set the player start tag to 2 on the level 2 or second player start on level 1 tag to 2? (if that makes sense…)
ok. You’re going to have to bare with me here. I realize it is frustrating but try and understand that I’m not experienced. when it comes to the save game to slot, what do I plug into it exactly?
I’m calling the open level on a level blueprint so how would I work that into the game instance?
For the Save game to slot, that is a way to store in the hard drive some data, you can check about that here. The game instance stores while the game is running. So for now just create an interger variable to store the last level and you set that variable everytime you leave a level. so if you are going from level 1 to 2, you store the 1 in the game instance right before you call the open level.
I’m hoping images will help you better apply it to what I need. what you’ve described so far seems like what I want, I may just be too stupid to understand fully.
For now, dont worry about the Save slot. What you are going to do is right before the open level node, you are going to do a get game instance node, cast it to your type and set the LocationStart_Int to the number of the level you are in. Then on the game mode before the for loop you do the get game instance and cast again to get the value of LocationStart_Int. Inside of the for loop you drag a wire out of the array element and you do get player start tag. See if the tag is the same as the LocationStart_Int (you need to convert from int to text), if it is then that is the player start you are going to use.
Would it make a difference if I now had the ‘Open Level’ function within the door trigger as opposed to the level blueprint?
This is what I’ve taken from what you’ve said and it doesn’t seem to be doing anything in terms of spawning me at the player starts. When I enter the building, it spawns me at world location 0, 0, 0.
I’ve probably missed something or not done something right…