I’m currently working in a project with 3 different levels but using the same player character, as soon as I change the level the character goes back to its original position.
I would like to know if anybody knows how to keep the first-person character location and view on all 3 different levels.
Think about using Game Instance for that. It is valid as long as your game runs (level doesn’t really matter). You can store your player’s location and rotation there (open Game Instance blueprint, create variable and make it editable). Before changing the level, update this variable with player’s current location and rotation. You can do it by calling Get Game Instance and casting to your specific game instance “type”, then you can access it’s variables and do whatever you want.
After loading new level get the variable stored in game instance and set your player’s location and rotation to it.
Detailed Walk-through (done after request)
Create new blueprint class. Set Parent Class to GameInstance, name it for example “BP_MyGameInstance”.
Open Level Blueprint in your first level. Here you want to Get Game Instance (the one which we just created). Then you cast it to BP_MyGameInstance (or whatever name you picked). Then you can access variable which we created. You set it’s value to current player’s transform (location, rotation and scale). You do it just before opening new level in your game. It doesn’t have to be done in level blueprint, it was just faster for me to show this way. Make sure that the name of the level which you want to open is exactly the same as the level which you have in your Content Browser.
At this point when you run the game and press “F” button in the first level your player’s current transform will be saved and new level will be opened. Now we need to make sure that when the player’s actor will be created in the new level it’s location will be changed to the one saved in BP_MyGameInstance. To do it just open your player’s character blueprint (in my case it’s default FirstPersonCharacter and add the following in the Construction Script. I added nodes marked by red circle. “AttachToComponent” was already there by default. Nodes which I added simply get ours BP_MyGameInstance once again and then use stored player transform (the one which we saved just before opening the new level) to set player’s location.
Hi, thanks very much, it worked perfectly. I was playing around with the blueprint and I basically copy the blueprint of the 1st level to the 2nd level, I change F to G and ‘‘open level node’’ to FirstLevel so that I can go back and forward but it’s not working properly.
I can go back and forwards within between levels but the position and the views are lost, may I know why?