FB SDK "sometimes not loading"?


the facebook sdk is not loading sometimes.
Sometimes I get the response from the SDK, sometimes it’s not even called.

While I was working without the editor (engine only) on a small prototype, I never encountered such a behavior.

It took ridiculously long to find, because it fails silently and throws a null value somewhere else.

Is there some tutorial/example on how one should properly setup the FB SDK in playcanvas?

I am having a great problem with lack of resources to playcanvas.

We usually recommend bringing external dependencies into your project. So, adding a script for the Facebook SDK to your project and copying the contents into it.

That said, there is no particular reason it should fail to load. To load scripts we are just creating script tags and attaching them to the page.

You can also use the Script Priority feature (which is I admit somewhat hard to find). If you add a script to the script priority list it will be loaded before other scripts in the scene. This is useful for any scripts that are not “playcanvas” scripts, e.g. libraries and SDKs that you need in your project.

The Script Priority dialog can be found in the main menu (click the PlayCanvas logo in the top left).

1 Like

I just tried using the Script Priority feature and it did not change anything.

I also tried https://connect.facebook.net/en_US/sdk.js (via https) as the script URL, no change.
It sometimes works, and sometimes doesn’t.

Feel free to take my project apart and examine why the facebook SDK “sometimes” calls window.fbAsyncInit.

We are aborting this project with PlayCanvas and are going to implement it in Unity.
The Editor looks fancy, but trying to be productive with PlayCanvas is extremely frustrating.

Hope you guys improve on this in future versions.
We will have another look at PlayCanvas when debugging, development and documentation are greatly improved.

Could you please get a bit more specific, of what is frustrating?
It would be very valuable for us.

It looks like you were still including the SDK from FB’s CDN, so it was being loaded twice. I suspect this was causing problems with the callback.

When loading your original I could see that sometimes it wouldn’t trigger the FB dialog because of some kind of race condition. When I removed the sdk script from the SocialManager entity I found that the script loaded 100% of the time. See my fork here: https://playcanvas.com/project/359803/overview/asynctdfork

Sorry, you had a tough time getting up to speed. It’s always tricky getting started with new technology and whilst we try to maintain the docs as best we can, there are always places that fall through the cracks. I’ll update the docs to be more detailed about how to include javascript libraries. Hope your project goes well and you give us another try soon.


Which browser are you using?

I am running Chrome Version 43.0.2357.125 (64-bit) (Ubuntu)

I do not get the fbAsyncInit console.log reliably on your fork either.

This is on Chrome 45.0.2454.101 OS X

I’ve tried refreshing with both cache enabled and disabled and Chrome’s throttling emulation enabled at various levels.

Hi, we inteded to post this later, but as you already asked, we quickly noted the most important things:
This is mostly the negative feedback, we did have our “wow wtf this is just unreal!” moments concerning the performance in the examples and the google docs-style collaboration magic.

  • At first we wanted to use PlayCanvas Engine without the editor, because we dislike editor-centric workflows and prefer pure-code (editors only for level editing, not for script attaching etc)

  • This workflow was largely undocumented and the engine examples were all included in script tags,
    which is not how we would write an entire game. Thus getting a feel for how to build a simple app was quite difficult.

  • We read that PlayCanvas features an Entity Component System, but working with the Components felt as sluggish as it does with unity. We would have preferred to be able to write a system that iterates quickly over all components of a type without bothering with the Scene Hierarchy.

  • Is there a way to “see” the context in which the game is run?
    You can add a svg tag to draw UI (I read there’s no native UI system yet, and SVG is powerful after all),
    but you lose that in “some script”.

  • Finding the usages of scripts (what entities are they attached to) is something we were missing as well.

  • OOP with Javascript itself is a horrible experience. I hope ECMAscript 6 classes will be a cure.

  • We also were happy to read “opensource”, but the source is hard to read/navigate (JS) and from within your cloud-editor, “go to declaration” is a missing feature for this to be handy.

  • Coming from a Java background (Eclipse, Netbeans, IntelliJ), we are used to very intelligent IDEs and strong refactoring capabilities. The Javascript Ecosystem fails miserably when it comes to these feature.
    Your editor looks nice but lacks many features. When writing a script, I feel like I am blind, testing out if an entities scripts are accessed via “entity.script.” or “entity.scripts.”, for example.
    In comparison C# with MonoDevelop offers correct autocompletion.
    We tried JetBrains Webstorm, but it also has problems with autocompletion of PlayCanvas.

Lots of this is, of course: "The only upside of Javascript, is that it’s native in browsers. The language itself is a monster."
Basically, The Editor is beautiful, but the rest indeed felt like v 0.1x

the first try always works 100%, but when I refresh then, it sometimes works and sometimes doesn’t.

Do you know if window.fbAsyncInit has to be defined before the script is loaded? It seems that it’s a race condition on script loading order, but I don’t know much about the FB SDK.

In my previous example (engine only, no editor) I pre-loaded the sdk with requireJS before defining window.fbAsyncInit.
I didn’t have a race condition in that case.