x


Communication issue from Browser to Web Player

Hi all,

I'm currently trying to send information to a precompiled unity3d object from my html web page. What I did is the following.

I created a project with Unity3D and built it as a webplayer (not streamed). I tried to follow the tutorial on Unity page ( http://unity3d.com/support/documentation/Manual/Unity%20Web%20Player%20and%20browser%20communication.html ) but nothing happened with my GetUnity().SendMessage(...).

As debug-like solution, I tried to put document.write("...") around the SendMessage and I discovered that it cannot apply the SendMessage command (it only prints the "..." that is before the SendMessage call).

Do anyone have an idea on this issue? Notice that I can call an javascript alert from Unity object on the web page... But I cannot communicate in the other sense.

Cheers, -Patrick

more ▼

asked May 26 '10 at 07:26 AM

Patrick gravatar image

Patrick
1 1 1 1

Perhaps there's a syntax error? I recommend checking it out using Firefox plus the Firebug extension?

May 26 '10 at 08:06 AM Extrakun

Can you list the HTML, and Unity code?

May 26 '10 at 08:37 PM Cyclops
(comments are locked)
10|3000 characters needed characters left

2 answers: sort voted first

I found another way to do it. in your unity3d script, make a function that call an external javascript that send data to unity3d.

so in unity3d.. on start() method

Application.ExternalCall("setUserID", 0);

on browser

function setUserID(Void)
{   
     GetUnity().SendMessage( "webConnect", "setSessionId", "<?php echo $session['session_id']; ?>" ); 
}

and then in unity3d, on the same script as the first call, create another function

void setSessionId(string sessionString)
{
    try
    {
        _user.setSessionId(sessionString);
        guitext.setSessionText();
    }
    catch { Debug.Log("null session"); } 
}

if you do this, the javascript call will only be called after the unity instance fully loaded

more ▼

answered Jun 25 '10 at 01:40 AM

rpl oye gravatar image

rpl oye
65 5 5 15

Thank you! This info should be in the documentation.

Mar 23 '11 at 06:34 AM Gillissie
Oct 17 '11 at 08:41 PM BerggreenDK
(comments are locked)
10|3000 characters needed characters left

this is because the web player have not fully loaded, and yet you call the sendmessage function. there is some tutorial somewhere, i also am looking for it while i am writing this post.

i will post the link if i find it.

more ▼

answered Jun 22 '10 at 07:43 AM

rpl oye gravatar image

rpl oye
65 5 5 15

@rpl, you could have edited this Answer to include the code, there's no reason to start two different Answers.

Jun 25 '10 at 02:25 AM Cyclops
(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

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

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x831
x188
x53

asked: May 26 '10 at 07:26 AM

Seen: 3983 times

Last Updated: Oct 17 '11 at 08:41 PM