Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

801
Vistas
Unity firestore - How to run GetSnapshotAsync() right after CheckAndFixDependenciesAsync()?

using Unity, I am trying to intialize my the firestore using CheckAndFixDependenciesAsync() and getting a document from firestore using GetSnapshotAsync(). From a firebase article, it is possible to add a continuation for the task with ContinueWithOnMainThread as shown in the example here:

Debug.Log("Checking Dependencies");
FirebaseApp.CheckAndFixDependenciesAsync().ContinueWith(fixTask =>
{
    Assert.IsNull(fixTask.Exception);
    Debug.Log("Authenticating");
    var auth = FirebaseAuth.DefaultInstance;
    auth.SignInAnonymouslyAsync().ContinueWithOnMainThread(authTask =>
    {
        Assert.IsNull(authTask.Exception);
        Debug.Log("Signed in!");
        var successes = PlayerPrefs.GetInt("Successes", 0);
        PlayerPrefs.SetInt("Successes", ++successes);
        Debug.Log($"Successes: {successes}");
        auth.SignOut();
        Debug.Log("Signed Out");
    });
});

However, this is not the case for my project, where I want to use GetSnapshotAsync() instead to retrieve some 'level' data - everything inside the block is not running.

 private void Start()
    {
        Debug.Log("Database awake ");
        //check if all dependency is in project
        FirebaseApp.CheckAndFixDependenciesAsync().ContinueWith(task =>
        {
            string lvCode = "oHFxRAIpIHfT8moiYSl9";
            Debug.Log("Get level :" + lvCode);

            DocumentReference levelref = db.Collection("level").Document(lvCode);

            levelref.GetSnapshotAsync().ContinueWithOnMainThread(querySnapshotTask =>
            {
                //Debug.Log here is not ran
                Debug.Log("Completed? " + querySnapshotTask.Result);
                Debug.Log("Faulted? " + querySnapshotTask.IsFaulted);

            });
        });
}

Can someone explain why is this happening to my code and possibly provide some alternatives that use the ContinueWith methods? (as opposed to await and coroutine solutions)

over 4 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

Author of that article here 😃

I can't quite see if you're doing anything wrong, but my guess is that maybe you're doing a db = FirebaseFirestore.DefaultInstance outside of that block (ignore this if you're doing a lazy iniitalization). Calling that before CheckAndFixDependenciesAsync could be causing your issue (CheckAndFixDependenciesAsync verifies that DefaultInstance can be called without erroring out).

Subbing out your db reference might fix it:

private void Start()
{
    Debug.Log("Database awake ");
    //check if all dependency is in project
    FirebaseApp.CheckAndFixDependenciesAsync().ContinueWith(task =>
    {
        string lvCode = "oHFxRAIpIHfT8moiYSl9";
        Debug.Log("Get level :" + lvCode);

        DocumentReference levelref = FirebaseFirestore.DefaultInstance.Collection("level").Document(lvCode);

        levelref.GetSnapshotAsync().ContinueWithOnMainThread(querySnapshotTask =>
        {
            //Debug.Log here is not ran
            Debug.Log("Completed? " + querySnapshotTask.Result);
            Debug.Log("Faulted? " + querySnapshotTask.IsFaulted);

        });
    });
}

Also, pay close attention to any error logging, changing the first ContinueWith to ContinueWithOnMainThread might reveal more errors (some versions of Unity do fail to report errors in background tasks).

Finally it's worth checking that you actually do have Firestore setup with your current game. Assuming you have a google-services.json or GoogleService-Info.plist in your Assets/ directory, you can go to "Window>Firebase>Documentation": Menu open to "Window>Firebase>Documentation"

And click "Open in Console" to jump right to your project and double check that Firestore is setup: "Documentation" page open with "Open in Console" visible

If you do find that changing the first ContinueWith to ContinueWithOnMainThread fixes your issue completely, it could be worth filing a bug. Generally the Firebase libraries should be thread safe, and since Firestore is in beta maybe it's a use case that was missed.

over 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda