Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by diggerjohn · Nov 26, 2013 at 11:11 PM · browsercommunication

Unity/Browser com driving me crazy

I have been trying to use the examples provided with no success at all. http://docs.unity3d.com/Documentation/Manual/UnityWebPlayerandbrowsercommunication.html

I have followed this to the letter, not even getting the Application.ExternalCall to the browser.

I have found that the result of var u = new UnityObject2(); as specified in the link is that u is NULL. There is a note that that may happen if game is not fully loaded. So how to delay my call till the game is loaded. How can I tell that the player and assets are ready to go?

Comment
Add comment · Show 3
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image ArkaneX · Nov 27, 2013 at 09:29 PM 0
Share

Where exactly are you calling this new UnityObject2() code?

avatar image diggerjohn · Nov 27, 2013 at 09:58 PM 0
Share
     <script type="text/javascript">

         swfobject.registerObject("unityPlayer", "11.2.0");


         function kickit()
         {
             alert('GOT IT');
         }

     var u = new UnityObject2();


     u.initPlugin(jQuery("#unityPlayer")[0], "Example.unity3d");

     function SaySomethingToUnity()
         {
         
             
             if(u.getUnity() == null){
                 alert('IN Func and u is NULL');
             }
         
             //document.write("inFucncion");
             u.getUnity().Send$$anonymous$$essage("$$anonymous$$yObject", "$$anonymous$$yFunction", "Hello from a web page!");

             //u.getObjectById("UnityContent").Send$$anonymous$$essage("$$anonymous$$yObject", "$$anonymous$$yFunction", "Hello from web page");

             //document.getElementById("unityPlayer").Send$$anonymous$$essage("$$anonymous$$yObject", "$$anonymous$$yFunction", "Hello from a web page!");
             alert('PAST UNITY Call');
                  
         }

         

     </script>
avatar image diggerjohn · Dec 01, 2013 at 05:32 PM 0
Share

Thank you again for responding and taking an interest. Sorry for the delay, holiday time here.

I ran the test in Chrome and FireFox. In both cases I get "object, Object".

2 Replies

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by ArkaneX · Nov 27, 2013 at 10:12 PM

When you build your project with Web Player target, two files are in the output folder: xxxxx.html and xxxxx.unity3d. Please take a look at the content of html one - there are parts that must be included, in order for the whole stuff to work. Script used to dynamically include UnityObject2.js for example:

 <script type="text/javascript">
 <!--
 var unityObjectUrl = "http://webplayer.unity3d.com/download_webplayer-3.x/3.0/uo/UnityObject2.js";
 if (document.location.protocol == 'https:')
     unityObjectUrl = unityObjectUrl.replace("http://", "https://ssl-");
 document.write('<script type="text\/javascript" src="' + unityObjectUrl + '"><\/script>');
 -->
 </script>

Adding below code after above script should work properly. Adding it before will not, because UnityObject2 is not yet available.

 <script>
     var u = new UnityObject2();
     alert(u);
 </script>
Comment
Add comment · Show 6 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image diggerjohn · Nov 27, 2013 at 11:33 PM 0
Share

Thank you so much for responding!! But sadly I am still getting "undefined" for u.

avatar image ArkaneX · Nov 28, 2013 at 09:25 AM 0
Share

Please copy below script and paste it to an empty html file and then run it. Does alert show 'undefined' or '[object Object]'? Or maybe no alert is displayed and you have an error in browser console?

 <html>
     <head>
         <script type='text/javascript' src='https://ssl-webplayer.unity3d.com/download_webplayer-3.x/3.0/uo/jquery.$$anonymous$$.js'></script>
         <script type="text/javascript">
         <!--
         var unityObjectUrl = "http://webplayer.unity3d.com/download_webplayer-3.x/3.0/uo/UnityObject2.js";
         if (document.location.protocol == 'https:')
             unityObjectUrl = unityObjectUrl.replace("http://", "https://ssl-");
         document.write('<script type="text\/javascript" src="' + unityObjectUrl + '"><\/script>');
         -->
         </script>
         <script>
             var u = new UnityObject2();
             alert(u);
         </script>
     </head>
 </html>

EDIT: pleast test this in at least 2 browsers.

avatar image diggerjohn · Dec 01, 2013 at 06:14 PM 0
Share

With this added insight I have cut out the style tags in the html Unity produces and I am getting at least "object, Object" now ins$$anonymous$$d of "undefined". And I am getting past the if (u==null) test in my button. So I have a Unity Object now. But I am not hitting or passing the call to Unity. I have found three possible ways of doing that in the forums but none seem to be passing.

u.getUnity().Send$$anonymous$$essage("$$anonymous$$yObject", "$$anonymous$$yFunction", "Hello from a web page!");

             //u.getObjectById("UnityContent").Send$$anonymous$$essage("$$anonymous$$yObject", "$$anonymous$$yFunction", "Hello from web page");

             //document.getElementById("unityPlayer").Send$$anonymous$$essage("$$anonymous$$yObject", "$$anonymous$$yFunction", "Hello from a web page!");
             alert('PAST UNITY Call');

I have tried all three but never get to the last alert confir$$anonymous$$g I have gotten back from Unity.

avatar image ArkaneX · Dec 01, 2013 at 09:57 PM 0
Share

Converted your answer to comment, as it doesn't answer the question...

As to your problem - I think you're calling your method just after setting u variable, when Unity object is not fully loaded (`u.getUnity()` returns null). This causes an error which you can see in browser console, breaking execution of further script. That's why alert is not called.

To see that code from Unity page works, please add a function to your script, just as described in the documentation:

 function SaySomethingToUnity()
 {
     u.getUnity().Send$$anonymous$$essage("$$anonymous$$yObject", "$$anonymous$$yFunction", "Hello from a web page!");
 }

and then add a simple html to your code:

 <b onclick='SaySomethingToUnity()'>click me</b>

and try to click this after your app is loaded. Be sure to have a game object named $$anonymous$$yObject in your scene, with a script attached containing a function $$anonymous$$yFunction accepting one String parameter. For me it works perfectly.

avatar image diggerjohn · Dec 02, 2013 at 03:41 AM 0
Share

Thank you. I have done exactly that. In fact I have also tried ....

             //u.getObjectById("unityPlayer").Send$$anonymous$$essage("$$anonymous$$yObject", "$$anonymous$$yFunction", "Hello from web page");

and //document.getElementById("unityPlayer").Send$$anonymous$$essage("$$anonymous$$yObject", "$$anonymous$$yFunction", "Hello from a web page!");

I also have Application.ExternalCall ("$$anonymous$$yFunction2", "Hello from Unity!"); in Unity at Start on an object calling the browser and getting nothing. Very frustrating.

Show more comments
avatar image
0

Answer by diggerjohn · Dec 02, 2013 at 03:00 PM

After all of this something about your last suggestion/communication triggered the old brain cells. I have been trying to do this through the Flash build. I instead, this morning, tried a build of the Web Player and it all works as advertised. I wish I could do it through the Flash build though. Thank you all for sticking with me through this discovery process.

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

17 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Passing variable into Unity function from browser JS via ActionScript 1 Answer

UnityObject callback function never runs 2 Answers

change player possition via url 0 Answers

Need help for simple moveforward function in Unity Web Player and browser communication 0 Answers

Can't get SendMessage in webpage to send info to the web player 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges