Search Unity

Desperados Save Logic

Discussion in 'Scripting' started by Batuhan13, Mar 29, 2021.

  1. Batuhan13


    Apr 9, 2017
    Hi mates. Yesterday I played desperados 3 and I really liked that save system in my game but I really dont have a any idea from where I should start. In game it saves the moment when you load it returns to that moment every npc return to their own position when you saved. Normally in my level based games I was using player prefs for saving but unfortunately I dont have a any idea about it. Could give me some advice? Thanks again have a great day
  2. GroZZleR


    Feb 1, 2015
    There's really not a whole lot of mystery to it. When you save, loop through every single entity that contains data that needs to persist and write it to a file. On load, read all the data back, re-construct all the entities and return their state to what was in the save file. The hardest part is re-building references between objects, which will require you to start thinking of an GUID system as you can't save references directly. I do my loading in three phases: an internal state phase, an external state phase, then a final clean-up phase for anything else.

    As with anything in programming when you're new, start small and build from there. Create a test scene with two different objects that have some dummy activity, just so they have some state to capture, and build out a small saving and loading routine. No need to worry about saving it to a file just yet, keep the data locally and treat it like a hot reloading system. Once you have them successfully saving and reloading, then worry about adding the file.
    Joe-Censored likes this.