【问题标题】:Facebook sdk for unity shows NullReferenceException: Facebook object is not yet loaded. Did you call FB.Init()? on google internal test用于统一的 Facebook SDK 显示 NullReferenceException:尚未加载 Facebook 对象。你调用了 FB.Init() 了吗?在谷歌内部测试中
【发布时间】:2022-12-31 02:50:06
【问题描述】:

使用 Facebook 的 Unity SDK 开发适用于 Android 的 Unity 游戏,但在将游戏发布到 google play 内部测试后,它抛出 NullReferenceException。当我在 Unity 上测试本地 apk 时,它工作得很好。

日志猫

2022-08-21 21:20:15.811 26811-28518/? E/Unity: NullReferenceException: Facebook object is not yet loaded.  Did you call FB.Init()?
      at Facebook.Unity.FB.get_FacebookImpl () [0x00000] in <00000000000000000000000000000000>:0 
      at Facebook.Unity.FB.LogInWithReadPermissions (System.Collections.Generic.IEnumerable`1[T] permissions, Facebook.Unity.FacebookDelegate`1[T] callback) [0x00000] in <00000000000000000000000000000000>:0 
      at UnityEngine.Events.UnityEvent.Invoke () [0x00000] in <00000000000000000000000000000000>:0 
      at UnityEngine.EventSystems.ExecuteEvents.Execute[T] (UnityEngine.GameObject target, UnityEngine.EventSystems.BaseEventData eventData, UnityEngine.EventSystems.ExecuteEvents+EventFunction`1[T1] functor) [0x00000] in <00000000000000000000000000000000>:0 
      at UnityEngine.EventSystems.StandaloneInputModule.ProcessTouchPress (UnityEngine.EventSystems.PointerEventData pointerEvent, System.Boolean pressed, System.Boolean released) [0x00000] in <00000000000000000000000000000000>:0 
      at UnityEngine.EventSystems.StandaloneInputModule.ProcessTou\

FB初始化

void Awake()
    {
        Instance = this;

        MoreGame.SetActive(false);

        if (!FB.IsInitialized)
        {
            // Initialize the Facebook SDK
            FB.Init(InitCallback, OnHideUnity);
        }
        else
        {
            // Already initialized, signal an app activation App Event
            FB.ActivateApp();
        }

        initGameScene();
    }

    private void InitCallback()
    {
        if (FB.IsInitialized)
        {
            // Signal an app activation App Event
            FB.ActivateApp();
            FB.Android.RetrieveLoginStatus(LoginStatusCallback);
            // Continue with Facebook SDK
            // ...
        }
        else
        {
            Debug.Log("Failed to Initialize the Facebook SDK");
        }
    }

    private void OnHideUnity(bool isGameShown)
    {
        if (!isGameShown)
        {
            // Pause the game - we will need to hide
            Time.timeScale = 0;
        }
        else
        {
            // Resume the game - we're getting focus again
            Time.timeScale = 1;
        }
    }

【问题讨论】:

    标签: android facebook unity3d


    【解决方案1】:

    确保你没有处于统一调试模式。当我处于调试模式时,我遇到了这个问题。当我切换到发布模式时,这个问题就消失了

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多