Home > Back-end >  Unity Firebase SetvalueAsync() freeze game
Unity Firebase SetvalueAsync() freeze game

Time:12-16

When I send data to my database as shown below, the editor freezes, what is the reason? Why does the code freeze even though I run it asynchronously?

private IEnumerator SetCoinDB(int coinCount)
{
    var DBTask = databaseReference.Child("users").Child(firebaseUser.UserId).Child("coins").SetValueAsync(coinCount   User.Instance.coin);
    yield return new WaitUntil(predicate: () => DBTask.IsCompleted);
    if(DBTask.Exception != null)
    {
        Debug.LogWarning("Coin update problem");
    }
    else
    {
        Debug.Log("Coins updated normally");
    }
}

CodePudding user response:

This should help: https://firebase.blog/posts/2019/07/firebase-and-tasks-how-to-deal-with

With Unity you'll have to be careful to not lock the main thread which is easy to do when introducing co-routines.

  • Related