#Firease RealtimeDatabase

1 messages ยท Page 1 of 1 (latest)

storm oracle
#

Hello guys, i am trying to settup realtime database, following function prints Saved players data but realtimedatabase stays empty... any ideas?

public void SavePlayerData(PlayerData playerData)
    {
        var playerDataJSON = JsonUtility.ToJson(playerData);
        var reqSavePlayerData = database.Child("users").Child(firebaseUser.UserId).Child(PLAYER_DATA_KEY).SetRawJsonValueAsync(playerDataJSON).ContinueWithOnMainThread(result =>
        {
            if (result.Exception != null)
            {
                UIManager.Instance.OkDialog.ShowMessage("Failed to save PlayerData: " + result.Exception.Message);
            }
            else
            {
                Debug.Log("Saved players data");
            }
        });
    }

https://prnt.sc/nBLVANX7ivu-

Lightshot

Captured with Lightshot

storm oracle
#

looks like JsonUtility.ToJson is returning {} even tho playerData has fields

rich falcon
#

playerdata might either have types not supported by jsonUtility (type support there really sucks), or you forgot to add [System.Serializable] above the class definition of PlayerData

storm oracle
#

Forgot to close this thread ๐Ÿ™‚ Fixed it, class wos Serializable but turns out JsonUtility doesnt recognize properties... so public string Name {get;private set} doesnt work

#

Thanks ๐Ÿ™‚

trim grove
storm oracle
#

THanks

rich falcon
#

only thing I'm not sure about is if newtonsoft has as wide of a platform support for built unity games than jsonserializer (which should work on any platform)
but it might has the same support, not sure

trim grove
rich falcon
#

I just wanted to mention the compatibility aspect in case it turns out it has less broad support and you need to be sure to have support for x platform

#

sometimes a library might not be "officially supported" but might still work on a platform

trim grove