Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Uncaught ReferenceError: createUnityInstance is not defined

Discussion in 'WebGL' started by radiantboy, Dec 6, 2021.

  1. radiantboy

    radiantboy

    Joined:
    Nov 21, 2012
    Posts:
    1,593
    Getting this when I try to run my webgl game from my webspace, works fine if I do build & run, any ideas?

    Uncaught ReferenceError: createUnityInstance is not defined
    at HTMLScriptElement.script.onload ((index):108:9)

    Unity 2021.2.4f1
     
  2. MarcelPursche

    MarcelPursche

    Unity Technologies

    Joined:
    Mar 3, 2021
    Posts:
    44
    Hi,
    are there any other errors in the browser console? Maybe, the .loader.js or .framework.js is not loaded properly.
     
  3. ROBYER1

    ROBYER1

    Joined:
    Oct 9, 2015
    Posts:
    1,444
    Same issue here, just
    Code (CSharp):
    1. Uncaught ReferenceError: createUnityInstance is not defined
     
  4. MarcelPursche

    MarcelPursche

    Unity Technologies

    Joined:
    Mar 3, 2021
    Posts:
    44
    It is very likely that the .loader.js is not loaded then. Is there another error that says something like: "Error: .loader.js could not found" or a similar error. Maybe in the Chrome Developer Tools/Network Tab? Can you tell me what your configuration for the web server looks like and what files are in your build output?
     
    kalibcrone likes this.
  5. radiantboy

    radiantboy

    Joined:
    Nov 21, 2012
    Posts:
    1,593
    I stopped getting this somehow, I think when i turned on compression or something it went away, could also be down to the .htaccess file i tinkered with that, got webgl build running good with no errors and not even that one about it "could be faster" :)
     
  6. larryhems

    larryhems

    Joined:
    Jun 20, 2022
    Posts:
    2
    If you are using any script file and getting "Uncaught ReferenceError: 'createUnityInstance' is not defined " which means ‘createUnityInstance’ is either a variable or a method which you are trying to use before declaring it using var keyword. This means that there is a non-existent variable referenced somewhere. This variable needs to be declared, or you need to make sure it is available in your current script or scope otherwise , it will endup throwing this ‘createUnityInstance’ is not defined error . This usually indicates that your library is not loaded and JavaScript does not recognize the ‘createUnityInstance’.

    To solve this error: Load the jQuery CDN library at the beginning of all your javascript files/scripts which uses $/ jQuery, so that $/jQuery can be identified in scripts .

    There can be multiple other reasons for this issue:
    • Conflict with Other Libraries
    • Path to your library included is not correct
    • Llibrary file is corrupted
    • Working offline (when you use CDN)