I have a multi-scene unity project. I want to have the player go to the new scene and when he exits that scene to go to the previous scene and start from the point where he left off.
Example:
large world… many buildings. Some buildings you can go inside a new scene is loaded for the interiors. I need to be able to go to the point back in the world where the player went in the door when they leave the inside of the building (through the door) instead of the default point where I created him in the scene.
EricS
Use DontDestroyOnLoad to keep variables from one scene to the next. However, personally I wouldn’t use multiple scenes in this case. I’d just turn off/on the exterior/interiors as needed.
–Eric
I got that part, but I am trying to figure out how to set the players transform to the previous position.
I am using an empty gameobject and setting its transform to the players prior to the scene load (of scene “B”), but when I load the scene to go back to the original scene “A”, I need to know where to put the transform… Should I place it in a script for the player (like in the awake function and set it to the global (nondestroyed) gameobject??
Just not sure the load order of unity to know where to set the transform to make it work correctly.
Probably the easiest thing is to not have the player be destroyed, since that’s persistent between scenes. When you leave one scene, store the transform.position in a variable. Then restore that position when going back.
–Eric
And remember when using this approach, that the scenes are set up in such a way that, that the exit is in scene1 is in the same position as the entrance in scene2.
You better save the position in a Undestructable object, when any scene start, the player should look for that object and get the position he should be from it.
In this case you only need one variable, that is the position in the outdoor terrain, since the indoors scenes always start at the same position. In this case, you only look for that data when loading the outdoor terrain.
.org
Hay why not trying to make a set spawn point for when you leave the building. using a empty game object and position it infornt of the said building and then in the script of the enmpty game object tell it to grab the player and position the player to the transform of the empty game object
idk if this will exactly work…but i mean a fixed spawn poitn for when you leave that building might work…gl
Or store the offset from the entry and use it to create the new position. I had the same issue in Project Weasel AND everything moves (planets orbit stars, etc.) so a player lands on a planet and then takes off – the planet has moved, so you need to adjust accordingly).
But the basic approach is: create a DontDestroyOnLoad “game manager” object which keeps track of all your persistent state, including inventory and a stack of positions which can be “popped”.