Search Unity

WebGL error only on minimal template

Discussion in 'Web' started by Stamperino, Jul 14, 2019.

  1. Stamperino

    Stamperino

    Joined:
    Feb 23, 2017
    Posts:
    6
    This error shows in a browser message after my game starts:

    Error: The object returned from UnityLoader.instantiate() should be stored in a global variable on window somewhere. (e.g. window.gameInstance = UnityLoader.instantiate(...)

    The error occurs on the minimal template.
    The error does not occur on the standard template.

    This appears to be a bug, so i'll submit it tomorrow.
     
  2. Stamperino

    Stamperino

    Joined:
    Feb 23, 2017
    Posts:
    6
    So, due to Unity's bug report receivers being unable to read, or simply struggle with sentences longer than 8 words, they think that unityloader.instantiate is missing, even though I don't think the issue could be more clear than "UnityLoader.instantiate() should be stored in a global variable", so now they've moved on and stopped contacting me.

    So this fix is for you, random person reading this.

    The Default build html file, called "index", looks like this:
    <script>var unityInstance = UnityLoader.instantiate("unityContainer", "Build/WebBuild standard.json", {onProgress: UnityProgress});</script>


    The important part is the first starting bit:
    <script>var unityInstance = UnityLoader.instantiate...

    Note that the default template here uses "var unityInstance" as storage.

    The Minimal template html file looks like this:
    <script>UnityLoader.instantiate...

    Note that the minimal template doesn't use storage at all, you know, the thing wrong with this build out of the box.

    So, to remedy this, we just add the storage part in front it, to look like this:
    <script>var unityInstance = UnityLoader.instantiate...



    As for the cause of the error, it's probably because outside sources need a reference of your game to make changes inside of it, like syncing data in an online multiplayer game with websockets.
     
    Last edited: Aug 13, 2019
    yangamedev likes this.
  3. Schubkraft

    Schubkraft

    Unity Technologies

    Joined:
    Dec 3, 2012
    Posts:
    1,071
    Do you have a case ID for your submission?
     
  4. Stamperino

    Stamperino

    Joined:
    Feb 23, 2017
    Posts:
    6
    I do, Case 1169591