[英]Facebook sdk for unity shows NullReferenceException: Facebook object is not yet loaded. Did you call FB.Init()? on google internal test
Working on a Unity game for Android using Facebook's Unity SDK, but after publishing game to google play internal testing, it throws NullReferenceException.使用 Facebook 的 Unity SDK 为 Android 开发 Unity 游戏,但在将游戏发布到 google play 内部测试后,它抛出 NullReferenceException。 It worked perfectly when I tested on local apk bulit on Unity.
当我在 Unity 上测试本地 apk 时,它工作得很好。
Logcat日志猫
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 Initialize 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;
}
}
Make sure you are not in Debug mode in unity and this script is enabled on any game object. I was facing this issue when i was in debug mode.确保你没有处于统一的调试模式,并且在任何游戏 object 上启用了此脚本。我在调试模式下时遇到了这个问题。 When i switched to release mode this issue was gone.
当我切换到发布模式时,这个问题就消失了。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.