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
1
Question by XoetziX · Jun 05, 2021 at 10:34 PM · null

FirebaseDatabase.DefaultInstance.RootReference == null

Hello everyone,

I am actually trying to get my application working together with a Firebase Realtime Database. For some time getting the reference to the database worked fine. It is actually a quite simple line:

 FirebaseDatabase.DefaultInstance.RootReference

But now it returns null and I do not have an idea why?!

 private void InitializeFirebase()
     {
         Debug.Log("Initializing FirebaseManagerGame + DB");
         try
         {
             DBreference = FirebaseDatabase.DefaultInstance.RootReference;
         }
         catch (Exception e)
         {
             Debug.Log("Gotacha! " + e.Message);
             if (DBreference == null)
                 Debug.Log("DBreference is null");
             throw e;
         }

Output:

 Gotacha! Object reference not set to an instance of an object
 UnityEngine.Debug:Log (object)
 FirebaseManagerGame:InitializeFirebase () (at Assets/Scripts/FirebaseManagerGame.cs:72)
 FirebaseManagerGame:<Awake>b__4_0 (System.Threading.Tasks.Task`1<Firebase.DependencyStatus>) (at Assets/Scripts/FirebaseManagerGame.cs:44)
 System.Threading._ThreadPoolWaitCallback:PerformWaitCallback ()
 
 DBreference is null


Do you have any idea why?

By the way: WIthout the try catch block I do not see any exception. It simply does not work and the exception is hidden, which does not really make it easy to find the problem...

Comment
Add comment · Show 2
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
avatar image Llama_w_2Ls · Jun 06, 2021 at 10:02 AM 0
Share

How did you initialize the FirebaseApp instance? Did you use the config file from Firebase?

avatar image XoetziX Llama_w_2Ls · Jun 06, 2021 at 05:18 PM 0
Share

[EDIT: Problem solved see other reply]

Yes, indeed. I got the google-services.json from my Firebase project and added it to my Asset folder.

Then adding:

using Firebase; using Firebase.Database;


finally calling the InitializeFirebase() method above within the awake method:

 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);
         }



1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by XoetziX · Jun 06, 2021 at 05:43 PM

I just solved the problem, but I do not understand why... Hopefully anyone can explain it to me so that I can avoid similar problems in the future.

I used an empty game object and attached my 2 FirebaseManager scripts. The ...Auth script is only needed at my GameMenu scene, so I divided them. alt text

It turned out that attaching both scripts to one game object causes the curious problem mentioned above.

I solved it by creating another game object and attaching one of the 2 scripts to the new object so that at the end I have 2 game objects with each 1 script attached.

Are there maybe any competing actions taking place if both scripts belong to one game object?


firebasemanager.jpg (100.5 kB)
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

118 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

Related Questions

Array containing destroyed object = Null? 1 Answer

Find if no objects with tag exist 3 Answers

Checking for null elements in a subset? 1 Answer

How do I stop a function from executing? 1 Answer

Check if Array.GetValue(i) is null 1 Answer


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