Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Saving Game Data

Discussion in 'Multiplayer' started by digiross, Feb 6, 2019.

  1. digiross

    digiross

    Joined:
    Jun 29, 2012
    Posts:
    323
    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:
    257
    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