I’m experiencing a bit of confusion getting my first Facebook game off the ground. Everything works as it should when I play the game from the Editor & I’m able to login to Facebook with no problems. When I try it from the FB canvas, however, I receive the following error:
NullReferenceException: Facebook object is not yet loaded. Did you call FB.Init()?
As you can see from the script below, I’m calling FB.Init() in the Start function (I’ve also tried it in Awake, with no difference). I’ve included only a snippet of the script, as the rest is likely not relevant.
void Start()
{
// Initialize Facebook
FB.Init(SetInit, OnHideUnity);
}
private void SetInit()
{
// Debug.Log("Facebook initialization complete!");
if(FB.IsLoggedIn)
{
// Debug.Log("Logged into FB.");
FBLoggedInMenus(true);
}
else
{
FBLoggedInMenus(false);
}
}
private void OnHideUnity(bool isGameShown)
{
if(!isGameShown)
{
Time.timeScale = 0; // pause
}
else
{
Time.timeScale = 1; // unpause
}
}
public void FBLogin()
{
FB.Login("email,publish_actions", AuthCallback);
}
void AuthCallback(FBResult result)
{
if(FB.IsLoggedIn)
{
// Debug.Log("FB login worked!");
FBLoggedInMenus(true);
}
else
{
// Debug.Log("FB login failed!");
FBLoggedInMenus(false);
}
}
I’m a bit concerned because, while it’s great that everything works in the Editor, there isn’t much point if that’s the ONLY place it works, haha. Any suggestions would be greatly appreciated.
Should it be relevant, I’m hosting the game on my web server(Godaddy.com) & have an active SSL certificate. The build itself is in Development Mode, and I do have my FB AppID firmly in place in the Facebook → Edit Settings. If there’s any additional information I can provide, please let me know. Thanks!
PS: Thinking that it might be a permissions issue, I’ve also tried setting the FB.Login to just publish actions. Sadly, that didn’t help either.