Loading a scene multiple times additively - how to get the last loaded scene?

I split my project into many scenes - one scene for each location and one scene for each ship. Now this is working well in principle, I just load/unload scenes as you travel through the world and encounter certain locations and other vessels.

Now my problem is this: It is possible that the same scene has to be loaded multiple times (because 2 players might be using the same ship-type) - how do know which scene is the newly loaded one? If I do SceneManager.GetSceneByName it always returns the first one. Is there a good way to handle this?

You could make your own scene manager that stored the scenes in a way that’s convenient to you (maybe a variable for player1_ship and player2_ship, or maybe a Dictionary or list of scenes). GameObjects have a “.scene” reference, so you could have an object in each scene add it’s own scene to your custom scene manager in the GameObject’s start function.

So for example: when you go to load a scene, you would tell your scene manager you’re loading the current scene into slot 1. Then when your scene loads, a GameObject will give your manager a reference to the scene and your manager will know which slot to put the scene into.

Unfortunately it looks like when you unload a scene, it unloads all instances of that scene, and there doesn’t seem to be a way around that. You’ll have to be clever, maybe deleting the root object of the scene instead of unloading it (just be sure you unload it later so you don’t gobble up a ton of memory)