Search Unity

Persisting data between scenes

Discussion in 'Scripting' started by Greyfox1984, Oct 20, 2019.

  1. Greyfox1984

    Greyfox1984

    Joined:
    May 28, 2017
    Posts:
    1
    Hello there, I'm fairly new to Unity and I need some help!

    Im trying to make a card game. I've created a "Deck Manager", which loads the list of deck types from a text file, then using the names in the Text files creates a object("deck) and populates it with all the cards(Names,description, etc) from another Text file.

    This all works perfectly. My only question is:

    what would you suggest for me to pass the deck objects I need (say when the player selects them from a menu)to the next scene? I've read about the DontDestroyOnLoad but Im not entirely sure thats what I'm looking for or really how to go about using it haha

    Any suggestions?
     
  2. Here is a great introduction the techniques to persist data between scenes:


    I personally like to use "Blackboard"-classes to do this. Which means they are independent from the scene and the only job to keep data bits and pieces for other parts of my code.

    Now, obviously to preserve the view (for example every card of your deck visually), DontDestroyOnLoad is a must since that will preserve the game objects.
     
    ThySpektre likes this.