On level change,teleporting actor to where it was on previous level

Hello there!

After many 3 hours of trying and came up with nothing. What I want to achieve is when the level is switched I wanted the actor to be on where it was on the previous level.

What I’ve tried:

  1. I created a vector variable on
    gameinstance to store initial
    value(I think something might be
    missing also ignore the print string
    because I cannot get it to work,
    Event Init only calls when game is
    started.)[2]
  2. Onbutton press I set
    lastknownlocation value to
    actorlocation and teleport using
    lastknownlocation that we stored
    after opening selected level.[1]
  3. Also created test print on
    firstpersoncharacter so it really
    updates lastknownlocation after the
    button is pressed.[3]

But after I click on the level change button it still respawns at the default location.

Thanks!

Using a GameInstance is fine, but your logic should be different:

  • Before you Open the new level B, you save the current character position into Last Known Position Level A. This variable is inside your GameInstance.
  • Once you come back from level B, in your Begin Play event, you retrieve Last Known Position A from the GameInstance and Teleport your player there, so it starts from where he left off
  • If you want the same to work for Level B, you need a specific variable Last Known Position Level B, also inside your GameInstance, but the logic is the same
  • If you have so many levels that creating one variable per level is cumbersome, you can use arrays or maps

Here is a tutorial you can refer to: HTF do I? Save Variables between Maps ( UE4 ) - YouTube

Thanks for the help!
Here is what I did in FirstPersonCharacter as you said and it worked! If anyone interested take a look.

But when game starts it sets actor location to 0,0,0. Is there a way to fix this? Or I will getting around it somehow. I just wanted to learn.

Also is it possible to also camera location like where it was looking? Which function should I use to get it?