- Home /
Firebase - "Object reference not set to an instance of an object" - how to further analyse it?
Hello everyone,
I am using Firebase for authentication and for storing data. Now I have the curious problem that this initialization fails sometimes with the error "Object reference not set to an instance of an object" (with the InitializeFirebase method) and I have no idea how to get to the root cause.
This is my code:
public class FirebaseManagerAuth : MonoBehaviour
{
public static FirebaseManagerAuth instance;
[SerializeField] private PlayerDataSO playerData;
//Firebase variables
[Header("Firebase")]
public DependencyStatus dependencyStatus;
public FirebaseAuth fbAuth;
public FirebaseUser fbUser;
void Awake()
{
//Check that all of the necessary dependencies for Firebase are present on the system
FirebaseApp.CheckAndFixDependenciesAsync().ContinueWith(task =>
{
dependencyStatus = task.Result;
if (dependencyStatus == DependencyStatus.Available)
{
//If they are avalible Initialize Firebase
InitializeFirebase();
}
else
{
Debug.LogError("Could not resolve all Firebase dependencies: " + dependencyStatus);
}
});
if (instance == null)
{
instance = this;
Debug.Log("FirebaseManagerAuth - awake - instance was null");
}
else if (instance != null)
{
Debug.Log("Instance already exists, destroying object!");
Destroy(this);
}
}
private void InitializeFirebase()
{
try
{
fbAuth = FirebaseAuth.DefaultInstance; **ERROR HAPPENS HERE**
}
catch (Exception e)
{
Debug.Log("Gotcha - AUTH! " + e.Message);
//throw e;
}
if (fbAuth == null)
Debug.Log("INIT FirebaseManagerAUTH + fbAuth = null");
}
And this the output:
Gotcha - AUTH! Object reference not set to an instance of an object
UnityEngine.Debug:Log (object)
FirebaseManagerAuth:InitializeFirebase () (at Assets/Scripts/FirebaseManagerAuth.cs:68)
FirebaseManagerAuth:<Awake>b__5_0 (System.Threading.Tasks.Task`1<Firebase.DependencyStatus>) (at Assets/Scripts/FirebaseManagerAuth.cs:32)
System.Threading._ThreadPoolWaitCallback:PerformWaitCallback ()
Unfortunately, I have no idea why this reference is not always set correctly and how to further analyse it, since some "Firebase magic" happens here which I cannot control directly.
I would be very glad for any advice, since it fully blocks my development at the moment...
Answer by XoetziX · Sep 15, 2021 at 05:27 AM
I would be very grateful for any tipps how to solve or further analyse this problem!
Your answer

Follow this Question
Related Questions
Boolean Toggle Cross-Script No Worky? 1 Answer
"Object reference not set to an instance of an object" problem 1 Answer
Object reference not set to an instance of an object. 2 Answers
Null Reference Exception - Time.deltatime problem 1 Answer
NullReferenceException: Object reference not set to an instance of an object ? 1 Answer