Firebase crashes

Viewed 17

I'm trying to save player data from a Unity game to the firestone cloud, but when I start game mode, the game crashes. The logs show that it crashes on the line "topScoreRef.SetAsync(topScorePlayers).ContinueWithOnMainThread"

Thanks!

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Firebase.Firestore;
using Firebase.Extensions;

public class StorageDataGameToFirebase
{
    FirebaseFirestore _firebase = FirebaseFirestore.DefaultInstance;

    public void SaveData()
    {
        Debug.Log("StartSave");
        //Dictionary<string, object> topScorePlayers = new Dictionary<string, object> // saving with a dictionary
        //{
        //    {"Player1", 1},
        //    {"Player2", 10}
        //};

        DataGame topScorePlayers = new DataGame // saving with a Struct
        {
            PlayerId = "1adsa",
            TopScore = 10
        };
        Debug.Log("CreatedDictionary");
        DocumentReference topScoreRef = _firebase.Collection("DataGame").Document("TopScorePlayers");
        Debug.Log("CreatedReferensFile");
        topScoreRef.SetAsync(topScorePlayers).ContinueWithOnMainThread(tast =>
        {
            Debug.Log("Update TopScore");
        });
    }
}

[FirestoreData]
public struct DataGame
{
    [FirestoreProperty]
    public string PlayerId { get; set; }
    [FirestoreProperty]
    public int TopScore { get; set; }
}
0 Answers
Related