I have enemies and items that are meant to only be able to be killed/picked up once. Right now if I switch from scene A to scene B and back to scene A then all the enemies and items that were previously destroyed in scene A are respawned, which is not what I want to happen. I need scenes to sort of save everything about them when the player moves to another scene, and then resume when the player moves back to that scene. Note that my player, camera, and UI are DontDestroyOnLoad().
The easiest solution would be to just disable the scene and enable it later, but the right solution is a lot more complicated.
I’d have scene A instantiate those objects on Start() if they should.
public class Setup : Monobehaviour
public Transform CoolItemParent;
public Transform BossParent;
public GameObject CoolItemPrefab;
public GameObject BossPrefab;
public bool ShouldSpawnBoss = true;
public bool ShouldSpawnCoolItem = true;
… So then you’d need to create empty game objects for where the boss and item should spawn in Scene A, attach Setup on something in Scene A (maybe another empty game object called Setup?), then write some scripts that set ShouldSpawnX to false when the item is collected or boss is killed.
ShouldSpawnX bools are a stand-in for whatever persistent data storage solution you’re using. I guess the simplest would be to use PlayerPrefs. See more about that here: Unity - Scripting API: PlayerPrefs