Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by XoetziX · Sep 04, 2021 at 07:16 PM · database

FirebaseAuth.DefaultInstance competes with another instance -> only one works

Hello everyone,

I am observing a strange behaviour. Right after the start of my programm my FirebaseManagerAuth initializes the connection to firebase

 FirebaseAuth fbAuth = FirebaseAuth.DefaultInstance;

and in parallel my FirebaseManagerGame initializes the connection to the firebase database:

 DatabaseReference DBreference = FirebaseDatabase.DefaultInstance.RootReference;

I separated both in 2 classes assinged to 2 different game objects in order to keep each class smaller and easier to maintain.

Both Firebase actions seem to compete with each other because it is always only one of both which succeeds to get its reference. The other yields a "Object reference not set to an instance of an object". It seems to be some kind of racing condition because the "winner" changes from time to time.

If I deactivate one game object the initilization of the other always succeeds.


Can you help my to find an elegant way to solve this problem? I could probably put everything together in one class but as mentioned that is excatly not what I want.


Here is the relevant code:

FirebaseManagerAuth

 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;
         }
         catch (Exception e)
         {
             Debug.Log("Gotcha - AUTH! " + e.Message);
             //throw e;
         }
         if (fbAuth == null)
             Debug.Log("INIT FirebaseManagerAUTH + fbAuth = null");
     }

FirebaseManagerGame (Database)

 public class FirebaseManagerGame : MonoBehaviour
 {
     public static FirebaseManagerGame instance;
     [SerializeField] private PlayerDataSO playerData;
 
     //Firebase variables
     [Header("Firebase")]
     public DependencyStatus dependencyStatus;
     public DatabaseReference DBreference;
        
 
     void Awake()
     {
   // excatly the same as above. 
     }
 
     private void InitializeFirebase()
     {
         try
         {
             DBreference = FirebaseDatabase.DefaultInstance.RootReference;
         }
         catch (Exception e)
         {
             Debug.Log("Gotcha - GAME! " + e.Message);
             throw e;
         }
         Debug.Log("INIT FirebaseManagerGAME + DBreference: " + DBreference.ToString());
     }



Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by XoetziX · Oct 29, 2021 at 05:59 PM

The answer can be found here: https://stackoverflow.com/questions/69719567/firebaseauth-defaultinstance-competes-with-another-instance-only-one-works

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

130 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

The type or namespace name 'Data' does not consist in the namespace 'Mono' 0 Answers

Store level data on server using database 0 Answers

How do you send data from Android to PC? 0 Answers

Weird issue with List and for loop. 1 Answer

Bool condition is always resulting in false even when it seems impossible to be false even using debug lines to check 4 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges