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

How to save player data on a server

Discussion in 'Multiplayer' started by Chefix, Mar 6, 2023.

  1. Chefix

    Chefix

    Joined:
    Mar 14, 2017
    Posts:
    5
    Hello.

    I wanted to ask how should I be saving player data like inventory, position, stats, etc. on a server.

    Let's assume a scenario where the player is playing the game, and he picks up an item off the ground and now it should be added to his inventory. How am I supposed to update the server to add this item to the player's inventory?

    The only way I know of to implement this system is a RESTful POST request to the server once an item needs to be added to the player's inventory that is saved in a database.

    But if the game revloves around constantly picking up items, then the server would be bombarded with POST requests constantly.

    Is there a better way to hold a player's data on a server in real time?
     
  2. CodeSmile

    CodeSmile

    Joined:
    Apr 10, 2014
    Posts:
    5,533
    Yes, any realtime networking library such as Netcode for GameObjects, Fish-Networking, Mirror, Photon, ... supports synchronizing variables via UDP messages. POST isn't suitable for realtime games. It can be used to persist a player's state to a database after each level (for example) or whenever the flow of the game is slowed or interrupted, eg user entering a shop, dungeon or similar.