0

I know this question has been answered before, but I'm trying to figure out why it isn't working in my specific case.

I have a public static string declared.

public static string currentUserEmail;

After the user creates an account, I store the Email address as currentUserEmail, but when debugging currentUserEmail is null.

FirebaseAuth.DefaultInstance.CreateUserWithEmailAndPasswordAsync(EmailAddress.text, Password.text).
    ContinueWith(task =>
    {
        if (task.IsCanceled)
        {
            Debug.LogError("CreateUserWithEmailAndPaswordAsync was canceled.");
            return;
        }
        if (task.IsFaulted)
        {
            Debug.LogError("CreateUserWithEmailAndPasswordAsync encountered an error: " + task.Exception);
            return;
        }
        FirebaseUser newUser = task.Result;
        currentUserEmail = newUser.Email;

Later I use another script to access the string with SCRIPTNAME.currentUserEmail, but in both situations it returns null. How can I access newUser.Email from another script?

JohnZ12
  • 183
  • 3
  • 14
  • 1
    The value probably hasn't been populated from the firebase side at the time when you try to access it. Hard to say what your architecture is like, but you could have an action in `SCRIPTNAME` that the accessor subscribes to. Then you notify the subscriber when the value comes in – Felipe Oct 09 '18 at 22:33
  • 1
    Did you make sure to assign the `InputField` in the unity editor? i.e. either by dragging the Unity object into the field found in your script or by using `getComponent()` – Felipe Oct 09 '18 at 22:42
  • I figured out the problem. When debugging I didn't realize that the value is only assigned after each breakpoint and not during. Using the InputField I was able to capture the value. Thank you. – JohnZ12 Oct 09 '18 at 22:50

0 Answers0