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. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

Application.ExternalCall in WebGL

Discussion in 'WebGL' started by jimjim, Jun 5, 2015.

  1. jimjim

    jimjim

    Joined:
    Nov 11, 2009
    Posts:
    127
    Hi i am having some problems communicating with my browser in webgl by using Application.ExternalCall.my code is this:
    Code (CSharp):
    1. Application.ExternalCall(func);
    .
    I have tried 2 different ways to communicate with the browser i have embedded the javascript function in the generated index.html like this
    Code (CSharp):
    1.     <script type='text/javascript'>
    2.      function testScript()
    3.     {
    4.         alert("test");
    5.     }
    6.     </script>
    i have also tried to link to it by using external javascript. Like this:
    Code (CSharp):
    1. <script src="Release/scormS.js" type="text/javascript"></script>
    Everty time I get the exception error and the webGL program fails to load shown below:

    Code (CSharp):
    1. ReferenceError: SCOInitialise is not defined version3.js line 1 > eval:1:0
    2. "exception thrown: ReferenceError: SCOInitialise is not defined,@file:///C:/Projects/Internal%20Projects/unity5Upgrade/development/test/Unity_Pro%205_Template_v04_webGLTests/Builds/WebGL/version3/Release/version3.js line 1 > eval:1:1
    3. _JS_Eval_EvalJS@file:///C:/Projects/Internal%20Projects/unity5Upgrade/development/test/Unity_Pro%205_Template_v04_webGLTests/Builds/WebGL/version3/Release/version3.js:1:146032
    4. H4d@file:///C:/Projects/Internal%20Projects/unity5Upgrade/development/test/Unity_Pro%205_Template_v04_webGLTests/Builds/WebGL/version3/Release/version3.js:49:1122126
    5. Xto@file:///C:/Projects/Internal%20Projects/unity5Upgrade/development/test/Unity_Pro%205_Template_v04_webGLTests/Builds/WebGL/version3/Release/version3.js:21:992514
    6. Vto@file:///C:/Projects/Internal%20Projects/unity5Upgrade/development/test/Unity_Pro%205_Template_v04_webGLTests/Builds/WebGL/version3/Release/version3.js:21:991968
    7. ntg@file:///C:/Projects/Internal%20Projects/unity5U"[] index.html:28:6
    8.  
    9. "Invoking error handler due to
    10. Script error."
    I have seen a few forum posts regarding application.external.call who have similar problems to me. Does this work in webGL, or do I need to do something different, to get it to work?
     
    Last edited: Jun 8, 2015
  2. DudeGuy

    DudeGuy

    Joined:
    Jul 17, 2014
    Posts:
    19
    I can't say that I know exactly what's going on in your situation, but I've been using ExternalCall for some things in my WebGL application. I haven't tried embedding the javascript in a tag, but I do have javascript files in my template that are referenced in the index.html file.

    I define a method in the javascript file that I call by string name when using ExternalCall (and any parameters that the javascript function accepts).

    Is your method SCOInitialise? Perhaps the final 's' is supposed to be a 'z'? Sorry I can't help much more.
     
  3. jimjim

    jimjim

    Joined:
    Nov 11, 2009
    Posts:
    127
    I made a direct call in unity Application.ExternalCall and it worked. not sure why a direct call to the function worked though
     
  4. levwsr

    levwsr

    Joined:
    Jul 23, 2012
    Posts:
    68
    We reported this to unity a while back and were told the fix will be in 5.2. Meanwhile you can manually fix it by:

    1. Open WebGLSupport/BuildTools/lib/Eval.js in your Unity folder.

    2. Replace

    eval (str);

    with

    window.eval (str);