In my project I currently have two scenes, a dungeon (scene 1) and a town (scene 0)… When the game starts the player spawns at the position of GameObject “PlayerStart” in the town… If I enter the dungeon and leave it again, I want the player to spawn at “PlayerFromDungeon”-spawn point in my town-scene. How can I achieve that?
you could mark a gameobject with dontdestroyonload to prevent it beeing destroyed at scene change. this is a bit difficult as it gets newly generated when its scene is loaded again. so either you have a scene to construct those which is not loaded again or you check if they exist already and destroy the new ones.
the other way is static data in a class. look for singleton pattern.
As an alt to DontDestroyOnLoad, you can place In your code that is used to load your town coming from the dungeon the position of the dungeon exit in a PlayerPref then when the town is loaded and the script is run that spawns the player, have it read the saved PlayerPref so that the player is now spawned at the dungeon exit across town or wherever its located - lol.
I have never used DontDestroyOnLoad before… So if I have a GameObject in one scene with DontDestroyOnLoad in its script… Do I need to have that same GameObject in my other scene? I though I could specify the spawn points by making a “public transform spawn1; spawn2” and so on in a script and set bools to tell the engine which spawn point to spawn at depending on what the player does… (?)
I think you could have a scene that just created that object at game start up and then immediately went into the opening or saved scene. There are probably other ways. It is kind of an interesting circular problem. It’s like going back in time and meeting yourself. I haven’t actually tried it myself yet, either.