Search Unity

Saving objects when switching scenes

Discussion in 'Editor & General Support' started by lukewoodland, Jun 21, 2020.

  1. lukewoodland

    lukewoodland

    Joined:
    Sep 2, 2019
    Posts:
    1
    I am making a farming game and when I switch scenes and come back to the plant scene, all the plants are gone. I used DontDestroyOnLoad() but it brought the object to the other scene. Is there a way to save objects but not bring them to another scene like DontDestroyOnLoad() does?
     
  2. There is, but it isn't that simple as just a DontDestroyOnLoad.
    You need to find out where to store your data.
    Then you need to do it so when you switch scenes you don't lose that data.
    And then you need to figure out how to reapply the data when you come back to the original scene.
    The answer is it depends how many scenes you have, what kind of data you want to save and how you want to apply it.

    Here is a tutorial about how to bring data around between scenes, but you still need to figure out what data you need to save here and how to apply it when you enter in to the scene again.