Hello, i want to save a class to playfab player data (title), for example this class
class PlayerData
{
public int[] skins;
public int money;
}
How i can do that?
Hello, i want to save a class to playfab player data (title), for example this class
class PlayerData
{
public int[] skins;
public int money;
}
How i can do that?
Convert a class to a JSON string. You can use Unity’s built-in Json.Utility - simply save string returned from JsonUtility.ToJson(playerDataClassToSave) and then whenever you request user’s data from PlayFab just convert it back to actual PlayerData class - JsonUtility.FromJson<PlayerData>(jsonString)
And if you need help with using PlayFab, here is a snippet that should allow you to save data for a user
public void SetTitleData() {
PlayFabServerAPI.SetTitleData(
new SetTitleDataRequest {
Key = "PlayerData",
Value = JsonUtility.ToJson(playerDataClass)
},
result => Debug.Log("Set titleData successful"),
error => {
Debug.Log("Got error setting titleData:");
Debug.Log(error.GenerateErrorReport());
}
);
}
Thanks! But I’m so dumb in playfab, do you know how to get data?
You gotta learn then, you can’t just “get data”. Read the docs, I’m also using playfab in my game, it’s great, but you gotta learn it by reading the docs. You have create players, set data etc. I’ll post a links to get you started, have a read
https://docs.microsoft.com/en-us/gaming/playfab/what-is-playfab
Have a look at the left with all the filters, you’ll get to know how to use the authentication system, automation, multiplayer, economy etc. And you’ll first have to create a playfab develpor account and import it into your project and set it up, if any problems let me know!
Тhanks! All work, but i didn’t see my data in admin panel, can you help!
Which admin panel are you talking about, did you go on the developer.playfab.com website? Login, under your studio click on your game? And under build, clicked Players?
if not, you gotta create players. Show me what code you’ve got so far, have you integrated the playfab SDK into your unity project? Have you logged in using the Playfab editor extensions and link your studio’s game title?
Do you think using Playfab has any benefits over saving locally? Can playfab be linked to the Sign in with apple button? (I haven’t tried yet)
it has benefits for f2p games and gives you a good way to store stuff like inventory out of the box, and makes stuff like leaderboards easy and sharing data between users easy.
also yes accounts can associated it with steam logins, apple logins, google accounts device ids and many other things.
PlayFab is a fantastic tool - besides what passerbycmc said, cloud save is obviously better as it is safe for the user’s switching their devices. You can integrate Facebook features easily, like friend leaderboards, and from there you can fully control your players’ data - you can even write a script on their clod script platform to handle any custom needs like app invites with rewards, etc.