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:
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]
Onbutton press I set
lastknownlocation value to
actorlocation and teleport using
lastknownlocation that we stored
after opening selected level.[1]
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.
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