- Home /
"Facebook object not loaded yet" error
When I try to run
FB.Login("email,publish_actions", LoginCallback)
I get this error:
NullReferenceException: Facebook object is not yet loaded. Did you call FB.Init()? FB.get_FacebookImpl () (at Assets/Facebook/Scripts/FB.cs:23) FB.Login (System.String scope, Facebook.FacebookDelegate callback) (at Assets/Facebook/Scripts/FB.cs:111) Controller.Start () (at Assets/Scripts/Controller.cs:27)
I am running FB.Init (SetInit, OnUnityHide) and my SetInit and OnUnityHide functions are:
private void SetInit()
{
enabled = true;
}
private void OnUnityHide(bool isGameShown)
{
if(!isGameShown)
{
Time.timeScale = 0;
}
else
{
Time.timeScale = 1;
}
}
are you absolutely sure that you are not calling FB.Login before FB.Init responds via the callback function?
I don't know how to check whether Init() has responded. What I am doing now is: FB.Init (SetInit, OnUnityHide); if(!FB.IsLoggedIn) { FB.Login("email,publish_actions", LoginCallback); }
According to your code above, the SetInit callback function will be called when Facebook has properly initialized. It is only then that you can attempt to log in.
Answer by Swaminathan · Feb 18, 2014 at 12:12 PM
Sample code.. Do like this
In a fresh new script copy paste this and try deploy it in a device.
private void CallFBInit()
{
FB.Init(OnInitComplete, OnHideUnity);
}
private void OnInitComplete()
{
Debug.Log("FB.Init completed: Is user logged in? " + FB.IsLoggedIn);
}
private void OnHideUnity(bool isGameShown)
{
Debug.Log("Is game showing? " + isGameShown);
}
private void CallFBLogin()
{
FB.Login("email", LoginCallback);
}
private void LoginCallback(FBResult result)
{
if (result.Error != null)
print("Logged In");
else if (!FB.IsLoggedIn) {
print("Failed");
}
}
NOTE TO REMEMBER :
Call the CallFBInit() function in your void start.
Call the CallFBLogin() function inside a button click. like this
if(GUI.button)
{ CallFBLogin(); }
This will definetly work. but remember that you call CallFBInit() inside start.
Answer by Addyarb · Jan 22, 2016 at 03:33 PM
My issue was that I was deriving from a script that called FB.Init(), so it was being called twice which apparently un-initialized it.
A good way to debug this is to just write:
void Start()
{
Debug.Log(gameObject);
}
on one of your scripts that calls it. Then of course the one that inherits will also respond once you enter play mode.
However this won't work if you're not deriving from, but simply calling FB.Init() somewhere else. In that case you'll just have to track down said script.
Answer by sollywon · Feb 25, 2018 at 11:21 AM
In my case, I turn the Facebook object off at Editor and just turn it on at runtime ([your object name].SetActive(true))and the error message is gone! also, this is my Facebook initialization code as below:
private void Awake()
{
if (!FB.IsInitialized) {
FB.Init (() => {
if (FB.IsInitialized)
FB.ActivateApp ();
else
Debug.LogError ("Couldn't Initialized Facebook!");
},
isGameShown => {
if (!isGameShown)
Time.timeScale = 0;
else
Time.timeScale = 1;
});
} else {
Debug.LogError ("Facebook Activate App");
FB.ActivateApp ();
}
}
I hope it would be helpful!
Your answer
Follow this Question
Related Questions
Facebook SDK 3.1.2 for Unity - Trouble logging in on Android Devices 1 Answer
Posting to Facebook wall using HttpMethod.POST unity3D 0 Answers
Problem integrating webplayer in Facebook 0 Answers
FB.Feed() "properties" argument not working as expected 0 Answers
Facebook Post to wall FB.Feed issue in Unity Facebook SDK 1 Answer