- Home /
My Facebook WebGl instant game is stuck at start, whenever i start my game, it stuck at loading, what should i do?
whenever i launch my application , it stuck at 0% Loading screen and cant go beyond.After an hours of search, i have not found any answer about that problem yet. Any help will be appreciated.
Answer by ShaheerTahir · Sep 13, 2018 at 08:17 AM
I recently released a course on Udemy on how to port your Unity game to Facebook Instant without using external tools like Export2Canvas, and also how to interact with the Facebook instant library from a unity game.
https://www.udemy.com/creating-facebook-instant-games-using-unity/
Also I am working on a plugin to automate the whole process (leaderboards and facebook ads included), which i hope to release this week.
first five can get the course for free using the coupon code INSTANT4UNITY just make sure to leave a review
Answer by Trusty · Nov 17, 2018 at 05:49 PM
Well, all is explain in the doc but I admit it's not very clear if you are not familiar to HTML5. Maybe a bit late but for those who will face same issue :
Build your game for WebGl.
Edit index.html to add FBInstant support and call the inialize function as in the documentation /!\ Remplace the "WebGl.json" by your script name. This resolve the SDK error you should have seen ( don't know how you pass it )
<!DOCTYPE html> <html lang="en-us"> <head> <meta charset="utf-8"> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <title>Unity WebGL Player | FacebookSample</title> <link rel="shortcut icon" href="TemplateData/favicon.ico"> <link rel="stylesheet" href="TemplateData/style.css"> <script src="TemplateData/UnityProgress.js"></script> <script src="https://connect.facebook.net/en_US/fbinstant.6.1.js"></script> <script src="Build/UnityLoader.js"></script> <script>FBInstant.initializeAsync().then(function() { var gameInstance = UnityLoader.instantiate("gameContainer", "Build/WebGl.json", {onProgress: UnityProgress}); }); </script> </head> <body> <div class="webgl-content"> <div id="gameContainer" style="width: 960px; height: 600px"></div> <div class="footer"> <div class="webgl-logo"></div> <div class="fullscreen" onclick="gameInstance.SetFullscreen(1)"></div> <div class="title">FacebookSample</div> </div> </div> </body> </html>
Tell Facebook Your game is loaded. Add the StartAsync
-
function UnityProgress(gameInstance, progress) {
if (!gameInstance.Module)
return;
if (!gameInstance.logo) {
gameInstance.logo = document.createElement("div");
gameInstance.logo.className = "logo " + gameInstance.Module.splashScreenStyle;
gameInstance.container.appendChild(gameInstance.logo);
}
if (!gameInstance.progress) {
gameInstance.progress = document.createElement("div");
gameInstance.progress.className = "progress " + gameInstance.Module.splashScreenStyle;
gameInstance.progress.empty = document.createElement("div");
gameInstance.progress.empty.className = "empty";
gameInstance.progress.appendChild(gameInstance.progress.empty);
gameInstance.progress.full = document.createElement("div");
gameInstance.progress.full.className = "full";
gameInstance.progress.appendChild(gameInstance.progress.full);
gameInstance.container.appendChild(gameInstance.progress);
}
gameInstance.progress.full.style.width = (100 * progress) + "%";
gameInstance.progress.empty.style.width = (100 * (1 - progress)) + "%";
FBInstant.setLoadingProgress(100*progress);
if (progress == 1)
{
FBInstant.startGameAsync().then(function(){
console.log("Game Started");
});
gameInstance.logo.style.display = gameInstance.progress.style.display = "none";
}
}
Well done !
Your answer
Follow this Question
Related Questions
Unity 5 WebGL Facebook SDK UI Button Sharing not Working 0 Answers
popup blocker keeps coming back and browser deletes local storage in WebGL 0 Answers
WebGL build inside webview for Facebook messenger? 0 Answers
How create customize bg on facebook, unity WebGl? 0 Answers
WebGL, Facebook drag background image 0 Answers