android Facebook统一软件开发包显示NullReferenceException:Facebook对象尚未加载,您是否在Google内部测试中调用了FB.init()?

kmbjn2e3  于 2022-12-31  发布在  Android
关注(0)|答案(1)|浏览(142)

使用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;
        }
    }
zvokhttg

zvokhttg1#

确保你没有在Unity中处于调试模式,并且这个脚本在任何游戏对象上都是启用的。我在调试模式时就面临这个问题。当我切换到发布模式时,这个问题就消失了。

相关问题