Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

Object state consistency across scenes

Discussion in '2D' started by kstrous, Nov 26, 2021.

  1. kstrous

    kstrous

    Joined:
    Oct 26, 2021
    Posts:
    7
    Right now I have my game set up so the character moves scene to scene for different rooms, the problem with this is that when I re-enter a room all objects are reloaded.
    I need some objects to stay destroyed (or interacted with) because otherwise the player could re-enter a room to pick up a charm or fight a boss or whatever a million times. I have an additive scene where I keep my player and a game manager but this isn't a viable solution for charms and enemies because these objects should only exist while the player is in the same scene.
     
  2. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    36,947
    You could make an empty GameObject called CharmsAndEnemiesHolder and then:

    - parent ALL charms and enemies to that object

    - mark that root GameObject as DontDestroyOnLoad

    - call .SetActive(bool) on that root GameObject to enable/disable all items when and where you need them.
     
  3. kstrous

    kstrous

    Joined:
    Oct 26, 2021
    Posts:
    7
    Thanks! I think I'll try something along those lines, most likely I'll create something like a loadManager which keeps track of bool variables that are linked to save states(and use that to call setActive() for each object), I watched a video on saving and I think that should be doable. Otherwise you run into the problem that even the charmsandenemiesholder is being reset when the scene is reloaded so any thisObjectHasBeenDestoyed esque variables would also be reset to false.