Just a quick question - I have been google-ing for hours but have not found a solution. Still very new to Blueprints.
I’d like to change levels (multiple design solutions for a remodeling in archviz) but always keep the current position + orientation of the player.
This solution doesn’t work (level switching does, but it jumps to the FirstPersonCharacter position). Should I look in saving/loading game data or…?
You’re doing both (getting the player pawn location and setting the player pawn location) after the switching the level. You aren’t changing anything. You want to save the location of the player pawn before you switch levels and set the location of the player pawn to the saved location after you switched the level.
Thanks for the replies. Much appreciated! I think I implemented your suggestion but still , its back to the default position. I’m missing something basic here…?
Are these nodes within your FirstPersonCharacter class? If not you need to plug in GetPlayerPawn in each GetActorTransform and SetActorTransform like you did in the first post.
I haven’t switched levels during runtime so far but I assume the instance of your FPC in the old level is destroyed and a new instance of FPC is spawned in your new level. Therefore your stored transform isn’t available anymore. So you need to store the transform in a class that exists over different levels. The GameState or the GameMode do I guess. Those classes feel like a better place for logic that switches levels in my opinion anyway.
Just tried it out and I noticed I was wrong. There are new GameMode and GameState created when switching the level aswell. But you can store it in a GameInstance object.
Create a new GameInstance object: Rightclick on Content Browser -> New Blueprint Class -> Search for Game Instance and press select. Now make sure your game uses your newly created GameInstance object. Go to Edit->Project Settings->Maps & Modes-> Game Instance.
Open your GameInstance object and create the following nodes:
PePeeee, thanks a lot! That’s a very simple solution. I spend the morning creating a solution using game saves. It’s a bit more blueprint code (see pic).
One problem though; both our solutions don’t re-use/store the rotation of the player. If I switch levels with both our code, the head is turned in another direction. Sometimes its a small difference, sometimes is totally in another direction. Any suggestion how to fix that?
I guess you aren’t rotating the actor but (in case you’re using the FirstPerson template) you are rotating the controller. So you need to store its rotation. I guess you can get its rotation with the GetControlRotation node. And when loading the new level you call the nodes AddControllerPitchInput, AddControllerYawInput and AddControllerRollInput and plug in the inputs val the respective values of your stored rotation. I hope this will work out.
Thansk for your support Pepeeee. It works now. I tried your suggestion but still no luck. In the end it works using the simple solution below. Thanks a lot for your help!
Hi @Nashriq_09 I’m not sure where I did put that code anymore - its been a while and I switched to different (more complex) blueprints.
The issue here was; if you load another level, all variables you had stored in your character/pawn (like position & orientation) are lost. So, just before switching the level, you need to store those variables in a GameInstance and after loading the level you load those variables from that Gameinstance and apply them in your newly spawned character/pawn in the new level.