quickstart-unity: [Bug] fetching failure: http code 400 in Unity Editor

[REQUIRED] Please fill in the following fields:

  • Unity editor version: 2019.4.16f1, 2019.4.33f1
  • Firebase Unity SDK version: 8.1.0, 8.6.2
  • Source you installed the SDK: .unitypackage
  • Problematic Firebase Component: Remote Config
  • Other Firebase Components in use: Analytics, Database, Storage, Firestore
  • Additional SDKs you are using: Facebook, Appodeal
  • Platform you are using the Unity editor on: Windows
  • Platform you are targeting: Android
  • Scripting Runtime: IL2CPP

[REQUIRED] Please describe the issue here:

This issue was never fixed: (https://github.com/firebase/quickstart-unity/issues/1127) I also reported it some time ago, other folks also experienced it and reported it on issuetracker, but still no solution, nothing.

I managed to fix editor freeze after fetch error 400 by updating Unity to 2019.4.33f1 version because Unity stated they fixed this freeze in other versions, but fetch error 400 is still present in most cases when I initialize Firebase in Editor Play mode. Remote Config works on Android build without problems so far, sometimes it works once in 10 or so attempts in Unity Editor, but because it mostly doesn’t work in Unity Editor it’s impossible to test it there. I tried to reinstall Firebase with the latest version, tried both Unity 2019.4.16f1 and 2019.4.33f1, the issue is still there.

Is there any way to fix this?

Steps to reproduce:

Have you been able to reproduce this issue with just the Firebase Unity quickstarts (this GitHub project)? What’s the issue repro rate? (eg 100%, 1/5 etc) 90%

What happened? How can we make the problem occur? This could be a description, log/console output, etc. Install Remote Config, Analytics, Database, Storage, Firestore, use code below to initialize Firebase and play.

Fetch result in 9 attempts or so out of 10:

fetching failure: http code 400 UnityEngine.Debug:LogError (object) Firebase.Platform.FirebaseLogger:LogMessage (Firebase.Platform.PlatformLogLevel,string) Firebase.LogUtil:LogMessage (Firebase.LogLevel,string) Firebase.LogUtil:LogMessageFromCallback (Firebase.LogLevel,string) Firebase.AppUtil:PollCallbacks () Firebase.Platform.FirebaseAppUtils:PollCallbacks () Firebase.Platform.FirebaseHandler:Update () Firebase.Platform.FirebaseMonoBehaviour:Update ()

If you have a downloadable sample project that reproduces the bug you’re reporting, you will likely receive a faster response on your issue.

Relevant Code:

Firebase initialization code:

public class FirebaseInit : MonoBehaviour { DependencyStatus dependencyStatus = DependencyStatus.UnavailableOther; protected bool isFirebaseInitialized = false;

    public void Init()
    {
           FirebaseApp.CheckAndFixDependenciesAsync().ContinueWithOnMainThread(task =>
            {
                dependencyStatus = task.Result;

                if (dependencyStatus == DependencyStatus.Available)
                {
                    InitializeFirebase();
                }
                else Debug.LogError("Could not resolve all Firebase dependencies: " + dependencyStatus);
            });
    }

    private void InitializeFirebase()
    {
        // [START set_defaults]
        Dictionary<string, object> defaults = new Dictionary<string, object>();

        // These are the values that are used if we haven't fetched data from the
        // server
        // yet, or if we ask for values that the server doesn't have:
        defaults.Add("config_test_string", "default local string");
        defaults.Add("config_test_int", 1);
        defaults.Add("config_test_float", 1.0);
        defaults.Add("config_test_bool", false);

        FirebaseRemoteConfig.DefaultInstance.SetDefaultsAsync(defaults)
          .ContinueWithOnMainThread(task =>
          {
          // [END set_defaults]
          Debug.Log("RemoteConfig configured and ready!");
              isFirebaseInitialized = true;
              FetchDataAsync();
          });
    }

    private Task FetchDataAsync()
    {
        Debug.Log("Fetching data...");
        Task fetchTask = FirebaseRemoteConfig.DefaultInstance.FetchAsync(TimeSpan.Zero);
        return fetchTask.ContinueWithOnMainThread(FetchComplete);
    }
    //[END fetch_async]

    private void FetchComplete(Task fetchTask)
    {
        if (fetchTask.IsCanceled)
        {
            Debug.Log("Fetch canceled.");
        }
        else if (fetchTask.IsFaulted)
        {
            Debug.Log("Fetch encountered an error.");
        }
        else if (fetchTask.IsCompleted)
        {
            Debug.Log("Fetch completed successfully!");
        }

        var info = FirebaseRemoteConfig.DefaultInstance.Info;

        switch (info.LastFetchStatus)
        {
            case LastFetchStatus.Success:
                FirebaseRemoteConfig.DefaultInstance.ActivateAsync()
                .ContinueWithOnMainThread(task =>
                {
                      Debug.Log("Success");
                });
                break;
            case LastFetchStatus.Failure:
                switch (info.LastFetchFailureReason)
                {
                    case FetchFailureReason.Error: Debug.Log("Error"); break;
                    case FetchFailureReason.Throttled:
                        Debug.Log("Fetch throttled until " + info.ThrottledEndTime);
                        break;
                }
                break;
            case LastFetchStatus.Pending:
                Debug.Log("Latest Fetch call still pending.");
                break;
        }
    }
}
// TODO(you): code here to reproduce the problem

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Comments: 18

Most upvoted comments

Thanks for the info, @ORibn-dev and @RocksteadyDog. Since the issue couldn’t be replicated in the quickstart, it’s likely that the cause of this behavior lies in your project. At this point, it would be helpful if you could provide a minimal, reproducible example of your project.

Download https://github.com/firebase/quickstart-unity/tree/master/remote_config/testapp

  1. Enter Play Mode - Ok 👌 1a. Enter Play Mode Again - Ok 👌 1b. Exit Play Mode - Ok 👌

  2. Delete the file “remote_config_data” in the Project folder

  3. Enter Play Mode - Ok 👌 3a. Enter Play Mode Again - Throw Error ( fetching failure: http code 400)😢 - Exit Play Mode 3b. Enter Play Mode Again - Throw Error 😭 - Exit Play Mode 3c. Enter Play Mode Again - Throw Error 😤 - Exit Play Mode 3d. Enter Play Mode Again - Throw Error 😡 - Exit Play Mode 3…

  4. Close Unity

  5. Open Unity

  6. Go to step 1.

Unity editor version: 2020.3.23 Firebase Unity SDK version: 8.6.2 Problematic Firebase Component: Remote Config Platform you are using the Unity editor on: Windows 7 Platform you are targeting: Android Scripting Runtime: IL2CPP