|
metadata
This is a guide for people having trouble getting kongregate’s API to work with a Unity WebGL build. If you're just looking for a guide on uploading WebGL games without the API have a look at this one http://developers.kongregate.com/blog/unity-webgl
**Step 1**
Download the simple HTML shell from [kongregate’s blog](https://docs.kongregate.com/v1.0/docs/concepts-kongregate-shell)
**Step 2**
In your code when you want to submit a stat use
``Application.ExternalCall("parent.kongregate.stats.submit","MyStatName",myScore );``
where "MyStatName" is the name of the statistic you set when uploading your game to kongregate and myScore is the variable you want to submit.
**Step 3 (Optional)**
If you want a loading bar, you can head over [here](https://github.com/kongregate/webgl-preloader) for a pretty nice kongregate template :)
There's instructions for how to set it up over there.
**Step 4**
Build your game :)
**Step 5**
Put your index.html and your "Template" folder into your "Build" folder.
**Step 6**
Open the kongregate shell you downloaded in a text editor and change the line
`kongregateAPI.embedFrame("game.html?" + params);`
to
`kongregateAPI.embedFrame("Build/index.html?" + params);`
Add an **s** to the http on this line
`script type="text/javascript" src="http://www.kongregate.com/javascripts/kongregate_api.js"`
so It turns into this
`script type="text/javascript" src="https://www.kongregate.com/javascripts/kongregate_api.js"`
also change the width and height of id="contentdiv"
to the width and height of your game.
Save it.
**Step 7**
In your index.html change
`<script src="Build/UnityLoader.js"></script>`
to
`<script src="UnityLoader.js"></script>`
Also change
`UnityLoader.instantiate("gameContainer", "Build/Builds.json"`
to
`UnityLoader.instantiate("gameContainer", "Builds.json"`
And lastly change
`background-image: url("Build/Template/anthill.png");`
to
`background-image: url("Template/anthill.png");`
Or if you've replaced the anthil, change anthill.png to what ever your icon's called
**Step 8**
Turn the "Build" folder into a zip.
**Step 9**
When uploading your game to kongregate, under the "Game file" slot choose the kongregate shell.
Tick the "I would like to upload additional files for this game." box.
And under "Additional files" upload the “Release” folder.
Choose your icon and screen shots and tick all the boxes that apply.
Then under the "Statistics API" section press add a statistic.
Name the statistic the **EXACT** same name you used when submitting your stat in your code.
Tick the necessary boxes and press save.
Then press upload and hopefully your game should work, though you will need to submit at least one stat and reload your page for your stats tab to show up.
**Gifs/Images**
Some people are still having issues, so here's a gif of the process.

Folders


Hope this helps :)
Thanks to XmmmX99 the developer of “The Perfect Tower” for teaching me how to do this in the first place.
**Errors**
If you have a 404 error then check to see if there's something wrong with this line *kongregateAPI.embedFrame("Release/index.html?" + params);*
If your file isn't named index, it's not in the release folder, or you've made a typo then you'll get the 404 error.
**Edits**
Unity 2017 Has "Buid" instead of "Release" as it's folder name so changed that.
The older template no longer works in Unity 2017, so changed it to a new kongregate one.
|
|
|
metadata
Looks really helpful. Nice work!
|
|
|
metadata
I could’ve used this guide a few weeks ago but I sorted it out, hoping to publish my game soon :)
|
|
|
metadata
Thanks for the tipp with the own Background, didn’t think of that :D
|
|
|
metadata
> *Originally posted by **[DarkRainyKnight](/forums/4/topics/614955?page=1#posts-10303807):***
>
> Looks really helpful. Nice work!
Thanks!
> *Originally posted by **[DwalinTheDwarf](/forums/4/topics/614955?page=1#posts-10304332):***
>
> I could’ve used this guide a few weeks ago but I sorted it out, hoping to publish my game soon :)
Good luck with your game :)
> *Originally posted by **[MrUnecht](/forums/4/topics/614955?page=1#posts-10307023):***
>
> Thanks for the tipp with the own Background, didn’t think of that :D
You’re welcome!
|
|
|
metadata
> *Originally posted by **[JasonNumberXIII](/forums/4/topics/614955?page=1#posts-10344569):***
>
> Guide is great, but what about saving / loading game progress? Can you write some tips, please?
Hey, have you tried [PlayerPrefs?](http://docs.unity3d.com/ScriptReference/PlayerPrefs.html)
|
|
|
metadata
|
|
|
metadata
Where can I locate, “TemplateData”
|
|
|
metadata
> *Originally posted by **[zapleaf](/forums/4/topics/614955?page=1#posts-10369812):***
>
> Where can I locate, “TemplateData”
If you have selected a template other then “Minimal” in the “Resolution and Presentation” section of the WebGL Player settings in Unity, then you will get a “Template Data” folder in the directory you’ve built the game. But you don’t need a template for your game to work, Templates are just to show the player your game is loading :)
|
|
|
metadata
This does look quite useful and the api FAQ doesn’t cover WebGL specifically, so I’m going to sticky it, at least for now. I do realize we have too many stickies, but this will have to do until I consolidate some of the links. Thanks for making this, AwesometacularVG!
|
|
|
metadata
> *Originally posted by **[JohannasGarden](/forums/4/topics/614955?page=1#posts-10381502):***
>
> This does look quite useful and the api FAQ doesn’t cover WebGL specifically, so I’m going to sticky it, at least for now. I do realize we have too many stickies, but this will have to do until I consolidate some of the links. Thanks for making this, AwesometacularVG!
Thanks, I’ve reduced the character amount of the title so It doesn’t take up two lines.
|
|
|
metadata
I did everything said here but the callback _onLoadCompleted_ inside the kongregate shell html doesn’t get called.
If I try to use the kongregateAPI.getAPI() function outside the callback and try to submit stats an error appears saying that it can’t call “submit” of undefined.
|
|
|
metadata
Is this – [https://docs.kongregate.com/v1.0/docs/concepts-kongregate-shell](https://docs.kongregate.com/v1.0/docs/concepts-kongregate-shell) – the correct place to get the shell? I’m not sure what a shell is but I cannot find the “kongregateAPI.embedFrame(“game.html?” + params);” in the shell I downloaded from the named webpage.
|
|
|
metadata
> *Originally posted by **[steadmuffin](/forums/4/topics/614955?page=1#posts-10660921):***
>
> Is this – [https://docs.kongregate.com/v1.0/docs/concepts-kongregate-shell](https://docs.kongregate.com/v1.0/docs/concepts-kongregate-shell) – the correct place to get the shell? I’m not sure what a shell is but I cannot find the “kongregateAPI.embedFrame(“game.html?” + params);” in the shell I downloaded from the named webpage.
Yes that’s the place, kongregate improved their documentation recently, but It’s still the same shell.
In most text editors you can press Ctrl + F to find a line just put in
`kongregateAPI.embed` and you should get it. If you’re sure it’s not there send me a screenshot :)
Please follow Step 6 again as there’s been an important edit.
|
|
|
metadata
Hello,
It doesn't work for me. I have a 404 error. Maybe can you help me ?

|
|
|
metadata
I've followed this guide and now it works ^^ : http://developers.kongregate.com/blog/unity-webgl
|
|
|
metadata
Any examples on retrieving the score? I tested out the score and I think the submition worked, it is showing the correct amount when I test on this webpage https://docs.kongregate.com/v1.0/docs/server-api-high-scores
But I can't find how to integrate the retrieving code, any help with this?
|
|
|
metadata
> *Originally posted by **[JulianoS1](/forums/4/topics/614955?page=1#10889884)**:*
> Any examples on retrieving the score? I tested out the score and I think the submition worked, it is showing the correct amount when I test on this webpage https://docs.kongregate.com/v1.0/docs/server-api-high-scores
> But I can't find how to integrate the retrieving code, any help with this?
I've done it, you can see how here:
http://www.kongregate.com/forums/4-game-programming/topics/686429-retrieving-statistics-for-displaying-in-game
|
|
|
metadata
Thanks a lot, AwesometacularVG, this seems to be the only working way for me. It's also very easy to reproduce even if the effort may seem high. I'm deploying a Unity 5.6 WebGL game to Kongregate and want to post highscores and the ExternalCall never worked.
However, I'd like to add that you can't use the Kongregate API in either way without having Flash plugin enabled, because you need the Ansible flash object which does the AJAX stuff.
|
|
|
metadata
Regarding 5.6...
The template in the blog post no longer works, as 5.6 has changed the format of the templates.
Also, after removing the margin from the "minimal" template and manually adding the API script line, I'm getting this error when it tries to load the API:
>
> 15:57:44.840 Invoking error handler due to
> Error: Permission denied to access property "href" 1 UnityLoader.js:1:13592
This seems to be related to same-origin policy -- the game runs fine after this error (without API support however), and the error does not pop up if the script tag for the API is commented out.
4/13 edit: API seems to be working again.
|
|
|
metadata
This is the most helpful topic ever, thank you AwesometacularVG, you're awesome indeed.
|
|
|
metadata
Thanks this helped me a lot, it really is the most helpful topic, I have to agree.
|
|
|
metadata
Is there a way to connect to the Kongregate API via C# inside the Unity editor to be able to debug various transactions? It appears the only way to test the API is by uploading a release version of the game, which increases complexity of debugging and iteration times.
I've shipped a number of games on Steam and it's very easy to connect a dev version of the game to the SteamAPI. You basically initialize the SteamAPI to your particular AppID and off you go. I don't see anything like this in Kongregate.
I've also spoken to another co-worker that has shipped games on Kongregate before and it used to be a standalone piece you would embed directly in your project. But things apparently have changed quite a bit since then.
Any help would be appreciated, thanks!
|
|
|
metadata
So I've since gotten this to work, but I took a different approach. I now go through PlayFab and it seems to be a pretty clean implementation. I still don't like that I have to deploy the game in order to test Kongregate API related things, so piping messages to text inside Unity for the win.
[Step 1](https://api-stage.playfab.com/docs/getting-started/unity-getting-started)
[Step 2](https://blog.playfab.com/docs/tutorials/landing-players/kongregate-unity)
We needed something that will allow for decent cloud saving potential, and Kongregate doesn't provide that. PlayFab also has a wicked set of real-time analytics and provides most of what Kongregate provides, in a way you can develop. So I may just do all my stats etc in PlayFab and just echo them out to Kongregate too. Kongregate really needs to up their game and provide some of these critical capabilities.
|
|
|
metadata
I know this is a dead thread but I just wanted to say thank you so much! After nearly a week of frustration, your way works! The only thing that I was stumped on was the "Builds" name in the HTML code. I didn't realize that this was the name of your game, since it was so similar to the "Build" folder name. Once I changed this name to the name of my game, it worked like a charm! Thanks again AwesometacularVG for this spectacular tutorial!
|