Hi, im working on a small game that has to be multiplayer. The thing i want to know is, what and how is the best way to save data on the server?
What it should do is like: Every player that logs in should get his referencing money, guns etc inventory items. But i dont know the way to do it…
I tried WWWForm to load stuff, but i think thats not the safest way and i didnt get it to work. Using Data prefs is easy to change by the player itself.
How can i save the playerdata to the server i am using and load it by user login?
If the game has to be multiplayer saving some user information should not be that hard. It always comes with stuff for that.
What are you using for multiplayer/matchmaking or logging in?
The best (albeit not easiest) way would be a server running a database. Unity can communicate with this database through http requests (GET, POST, PUT mainly). At my last workplace we used the BestHTTP plugin for one project (Unity frontend), can’t give you any details on the server backend, though, since that was done by a colleague of mine.
In what case? We have around 50 servers available to host it on haha
But i thought about saving the XML to the user file and then let it upload and delete again, but i think thats not the best way as people gonna abuse the way of saving the XML file and/or editing it…
If you want to save it local I wouldn’t save it as XML no, rather save it as binary data as most users won’t be able or bother to manipulate that. Then you can just use load that data in memory and persist it to the server using WWWForm.
[Serializable]
public class SaveableData
{
// Saveable fields. You could also use public fields, but that goes against normal C# conventions.
[SerializeField] private int score;
public SaveableData(int score)
{
this.score = score;
}
public int Score { get { return score; } }
}
public class Level : MonoBehaviour
{
[SerializeField] private string levelName;
[SerializeField] private int levelScore;
private void SaveLevel()
{
var data = new SaveableData(levelScore);
DataManager.SaveData<SaveableData>(data, levelName + "_save");
}
private void LoadLevel()
{
var data = DataManager.LoadData<SaveableData>(levelName + "_save");
if(data != null)
{
levelScore = data.Score;
}
}
}