I'm getting a null reference error when testing the login and register functions in the Unity app I'm building. Both errors are virtually the same line of code, so I'm guessing that something isn't connecting with Firebase correctly.
I'm using Unity 2021.1.12f1
Here is the relevant code (didn't want to post too much, hoping that this is enough to help diagnose the problem.
public class FirebaseManager : MonoBehaviour
{
public static FirebaseManager instance;
public FirebaseAuth auth;
public FirebaseUser user;
FirebaseApp.CheckAndFixDependenciesAsync().ContinueWith(checkDependencyTask =>
{
var dependencyStatus = checkDependencyTask.Result;
if (dependencyStatus == DependencyStatus.Available)
{
InitializeFirebase();
}
private void InitializeFirebase()
{
auth = FirebaseAuth.DefaultInstance;
auth.StateChanged += AuthStateChanged;
AuthStateChanged(this, null);
}
public void RegisterButton()
{
StartCoroutine(RegisterLogic(registerUsername.text, registerEmail.text, registerPassword.text, registerConfirmPassword.text));
}
private IEnumerator RegisterLogic(string _username, string _email, string _password, string _confirmPassword)
{
if (_username == "")
{
registerOutputText.text = "Please enter a username";
}
else if (_password != _confirmPassword)
{
registerOutputText.text = "Passwords do not match";
}
else
{
var registerTask = auth.CreateUserWithEmailAndPasswordAsync(_email, _password);
//code continues from here
That last line is where the Null Reference error gets thrown whenever I click the "Register" button. (There's a similar line of code in the Login function that throws the same error, so I'm assuming the root is the same.)
What I've done to attempt to fix this:
- Verified that the json file is in the Assets folder
- Restarted Unity
- Deleted and reinstalled the Firebase packages (auth, database, and remote config)
I'm really at a loss here, any help would be greatly appreciated.