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
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

how to save scene and load objects in 2d platformer

Discussion in 'Scripting' started by Masashi86, Nov 9, 2016.

  1. Masashi86

    Masashi86

    Joined:
    Jul 9, 2014
    Posts:
    7
    Hi,
    I'm wondering, that how I could save and load objects in game in a 2d platformer, so that if the player collects an object(s), leave the scene and return back that scene later, the collected object(s) is(are) destroyed or deactivated.
    What could be good way to do this?
     
  2. Defero

    Defero

    Joined:
    Jul 9, 2012
    Posts:
    200
    Depends, if you need this information for only the current instance of the game (meaning, that after the player closes your game, this information is not relevant anymore), you can store some unique identifiers in some class, and put the game object on the DontDestroyOnLoad.
    Then everytime you start/restart your scene, check if there's anything in there waiting for you.

    If you need this information to be persistent between the closing and opening the whole game, you will have to store it as such also.
    Maybe something like this:
    http://wiki.unity3d.com/index.php/ArrayPrefs2

    Regards