Code gets ignored

can anyone explain why following line gets ignored: panelTest.SetActive(true);
full function code:

   public void getBaseData()
    {
        Dictionary<string, object> data = null;
        if (firebase.getFirebaseAuth().CurrentUser == null)
            return;

        firebase.getDb().Collection("users").Document(firebase.getFirebaseAuth().CurrentUser.UserId).GetSnapshotAsync().ContinueWith(task =>
        {
            if (task.IsCompleted)
            {
                DocumentSnapshot snapshot = task.Result;
                if (snapshot.Exists)
                {
                    Debug.Log("Data found:");
                    data = snapshot.ToDictionary();
                    panelTest.SetActive(true);//gets ignored
                }
                else
                {
                    //no entry for that user
                    Debug.Log("snapshot doesnt exist");
                }
            }
           
        });
    }

i dont get any error messages; also the line panelTest.SetActive(true); works fine outside the function.

I assume “Data found:” is being properly logged to the console, i.e. you know this part is being executed?

You are using Tasks (i.e. async/await), where you need process unhandled exception explicitly. If you don’t use the async/await keywords, you need to check Task.IsFaulted and log Task.Exception, otherwise you’ll never know if there was an unhandled exception.

In your case, ContinueWith gives you a task, which you don’t properly check (IsCompleted returns true for faulted tasks), and also returns a new task, which you discard but also need to check.

Besides this, it’s always also possible that the line actually gets executed but something else is immediately deactivating the object again, so it only seems like the line was ignored. Connecting a debugger is usually the fastest way to check if the line is actually executed.

1 Like

Much of what @Adrian said about verifying the code is running, make sure your target is correct and not being turned off quickly after, etc.

But also…

Try using
ContinueWithOnMainThread

instead of
ContinueWith

1 Like

that makes sense! thank you for your relpy !!!

thank you for your explanation! it really helped