Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

Saving Player States to a server

Discussion in 'Multiplayer' started by heinickesg, Jun 2, 2014.

  1. heinickesg

    heinickesg

    Joined:
    Jan 25, 2013
    Posts:
    48
    Hi Everyone,

    I have been looking for this information for far longer than I wish to admit. I can not for the life of me seem to find any information regarding saving player state. Here is what I want to do:

    I have a player prefab that is spawned in (not part of the scene originally) This is handled by none other than photon networking.

    What I want to be able to do at the very least, is simple save the player's position to some form of online database. This way they can access it from other PC's as well as save progress. I can not find any information regarding how to hook up a database for storing this information.

    Long story short, When the player prefab is created I want it saved, everything on the prefab remains intact and loads when the player comes back to play.

    AT the very least i want to save the player position.

    I want this saved to a server, not on the player's client to avoid cheating and allow log in from other places.

    Any ideas? Can someone point me in the right direction?
     
  2. CJSadler

    CJSadler

    Joined:
    Oct 1, 2012
    Posts:
    5
    See if this video is any help.

     
  3. heinickesg

    heinickesg

    Joined:
    Jan 25, 2013
    Posts:
    48
    Kinda gives me an idea, Will this work in unity though? Do not see him even mention unity.
     
  4. CJSadler

    CJSadler

    Joined:
    Oct 1, 2012
    Posts:
    5
    You should be able to import the dll's into your project and use them with unity.
     
  5. JamesPro

    JamesPro

    Joined:
    Mar 5, 2012
    Posts:
    509
    Depends what version of the .net runtime the dlls for that database are compiled in. If they are compiled for any version greater then like 3.5 then it won't work.

    Pretty much what you want to do is have the Server Control all movement. The Server would then be the one to connect to the Database and save the information. You NEVER want the Client to connect directly to the Database.
     
  6. heinickesg

    heinickesg

    Joined:
    Jan 25, 2013
    Posts:
    48
    Yeah I have heard not to allow the client to connect directly, Are the DLLS located in the unity install folder? At this point I just want to save some simple values (player XYZ and money to name two)
     
  7. nastasache

    nastasache

    Joined:
    Jan 2, 2012
    Posts:
    74
    You can use WWW class to write/read data at any time you wish to an online database, simple calling a server side script, for example PHP to write/read to MySQL.
     
  8. heinickesg

    heinickesg

    Joined:
    Jan 25, 2013
    Posts:
    48
    Hmm yeah that is true, I think I will look up how to generally access database info with PHP/C# then figure out how to get unity to be happy with it.