I’m currently working with the latest Firebase SDK v7.1.0 and Google Play Games for authentication, data storage and database reading. I have stuck for over 3 days trying to figure out what the problem is.
This is my code :-
using System;
using Firebase;
using UnityEngine;
using Firebase.Database;
public class UpdateChecker : MonoBehaviour
{
public GameObject updateAvailableScreen;
static string s_DatabaseURL = "firebase-database-path-is-hidden-for-privacy-reasons";
static float s_DatabaseVersion = 1.0f;
static float s_GameDataVersion = 1.0f;
public static string databaseURL
{
get { return s_DatabaseURL; }
}
public static float databaseVersion
{
get { return s_DatabaseVersion; }
}
public static float gameDataVersion
{
get { return s_GameDataVersion; }
}
void Start()
{
//CheckForUpdates();
}
public void CheckForUpdates()
{
FirebaseDatabase.GetInstance(s_DatabaseURL).GetReferenceFromUrl(s_DatabaseURL + "/Version").GetValueAsync().ContinueWith(task =>
{
// Check if the task has any errors
if (task.IsFaulted)
{
// Debug the errors
FirebaseException exception = task.Exception.Flatten().InnerExceptions[0] as FirebaseException;
Debug.Log(exception.Message);
}
// Check if the task has completed
else if (task.IsCompleted)
{
// Parse the data
DataSnapshot rawData = task.Result;
float version = Convert.ToSingle(rawData.GetRawJsonValue());
s_DatabaseVersion = version;
Debug.Log("Database Version: " + s_DatabaseVersion + ", Application Version: " + s_GameDataVersion);
// Check for data
if (s_DatabaseVersion > s_GameDataVersion)
{
// Update is available
Debug.Log("Update is available!");
updateAvailableScreen.SetActive(true);
Debug.Log(true);
}
else
{
// Update is not available
Debug.Log("No updates!");
}
}
});
}
}
Here the updateAvailableScreen
is a Canvas
whose reference I have assigned in the Inspector.
When the update is available, the first Debug statement works which would notify gamer about an update. But when it comes to enabling the gameobject with SetActive(true)
, it does not work. I did a lot of research and no one seems to have this issue. I tried debugging and found that wherever I wrote the reference for updateAvailableScreen
, Unity seems to return the whole function. Nothing below it gets executed. I messed around a lot, tried debugging but found no clue. Again, here, only half of the function/task is getting executed. I don’t know for what reason is this happening.
If anyone knows how to solve this, please be sure to answer. Thanks in advance.