Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

WebGL: ReferenceError: UnityObject2 is not defined

Discussion in 'Web' started by quaigon, Jul 7, 2015.

  1. quaigon

    quaigon

    Joined:
    Aug 16, 2013
    Posts:
    8
    I try to load the index.html with the webGL build from our project. But it stops with the first screen and this error message appears:
    Yes, there is no UnityObject2 defined in the index.html, because it isn't needed. I used the standard Unity WebGL Template.

    The only communication is from the UnityScene to the Html-File to open a url in a new tab.
    Code (CSharp):
    1. void OpenURL () {
    2.   Application.ExternalCall("OpenNewTab", url);
    3. }
    Code (JavaScript):
    1. <script type="text/javascript">
    2.   function OpenNewTab(url) {
    3.      window.open(url, "_new");
    4.   }
    5. </script>
    As Webplayer Build it works fine.


    Which objects generate the UnityObject2 request? How can i get closer to a solution?


    (Unity 5.1.1.f1, Firefox 39.0)
     
  2. liortal

    liortal

    Joined:
    Oct 17, 2012
    Posts:
    3,562
    UnityObject2 is related to the WebPlayer, and not to WebGL.

    Are you getting a longer trace of where the issue is coming from ? try to look in the JS console of your browser.
    Also, there's another possibility that your c# code is "injecting" custom JS code at runtime.

    You can try to look for unityobject2 in all of your project source files, maybe something will turn up that is adding it (we also used something similar in the past, so it's not so far fetched).
     
    quaigon likes this.
  3. quaigon

    quaigon

    Joined:
    Aug 16, 2013
    Posts:
    8
    Thank you. It was a 3rd party plugin, which i can't rember. So the hint to look in the project source files was the right one.
    Shame on me. :D
     
    liortal likes this.
  4. liortal

    liortal

    Joined:
    Oct 17, 2012
    Posts:
    3,562
    Don't be so hard on yourself :)
     
  5. Stranger-Games

    Stranger-Games

    Joined:
    May 10, 2014
    Posts:
    393
    Hi @quaigon

    Sorry to ask something a little different from the thread, but when you use that OpenNewTab method, does the browser block the popup?
    I use chrome and your technique and the popup is blocked unless I add exception.
    I trigger the Application.ExternalCall("OpenNewTab", url); in a unity UI with Pointer Down event response.

    Thank you for advance!
     
  6. quaigon

    quaigon

    Joined:
    Aug 16, 2013
    Posts:
    8
    Hey,
    in this project, the html handling isn't my job. but yes, we have the same behaviour with google chrome. but at the moment, our UnityPlayer is on a popup window. so the user has to unblocked it anyway. but good to know that there will be a problem, when we integrate the 3d-window in the webpage. i have to ask the web-developer for a solution.
     
    Stranger-Games likes this.
  7. Stranger-Games

    Stranger-Games

    Joined:
    May 10, 2014
    Posts:
    393
    Thank you for your reply. Did the developer find a solution?