Search Unity

  1. Unity 2019.1 beta is now available.
    Dismiss Notice
  2. The Unity Pro & Visual Studio Professional Bundle gives you the tools you need to develop faster & collaborate more efficiently. Learn more.
    Dismiss Notice
  3. We're looking for insight from anyone who has experience with game testing to help us better Unity. Take our survey here. If chosen to participate you'll be entered into a sweepstake to win an Amazon gift card.
    Dismiss Notice
  4. Want to provide direct feedback to the Unity team? Join the Unity Advisory Panel.
    Dismiss Notice
  5. Unity 2018.3 is now released.
    Dismiss Notice
  6. Improve your Unity skills with a certified instructor in a private, interactive classroom. Watch the overview now.
    Dismiss Notice

Saving Game Data

Discussion in 'Connected Games' started by digiross, Feb 6, 2019.

  1. digiross

    digiross

    Joined:
    Jun 29, 2012
    Posts:
    177
    I'm working on a FPS with some RPG elements. I'm not new to Unity, however I'm new to multiplayer aspects of saving game data so I'm looking for advice/point in the right direction.

    For my game I need to store a lot of server side player data, inventories, building upgrades, etc.

    Is there an asset on the Unity store that would be a good jumping point. Most seem to be a mixed bag and data access being fast and reliable is key.

    Thanks in advance
     
  2. PhilippG

    PhilippG

    Joined:
    Jan 7, 2014
    Posts:
    249
    Saving gamestate to binary is not too hard to do actually, and you would have full control over how it works, something like this:
    Code (CSharp):
    1. BinaryFormatter bf = new BinaryFormatter();
    2. string path = Application.persistentDataPath + "/" + filename + ".save";
    3. FileStream file = File.Create(path);
    4. bf.Serialize(file, GameData.Current);
    5. file.Close();
    GameData.Current would be the current world state, containing anything you want to be serialized, ie a list of players data. You'd just need to figure what would be needed to be saved to restore the state you had.

    Edit: In mutliplayer you'd have some more choices to do, like whether you want players to keep their character seperate from the game state or if you'd like keep the player characters integrated in the game state. If they are integrated, you need a way for them to select characters again when they rejoin the game
     
    Last edited: Feb 7, 2019