How to debug GetUnity().SendMessage?

Hi all,

I am trying to use the following code from the web browser in order to update the player name in my game:

GetUnity().SendMessage(“3rd Person Controller”, “initSetPlayerName”, “Player 1”);

However, nothing seems to happen, so I was wondering if someone would have an idea how I can debug this. There are no javascript errors in the browser and GetUnity() returns a valid object.

I also did the following in the game just to check that my game object and function names are correct and that worked ok:

GameObject test=GameObject.Find(“3rd Person Controller”);
test.SendMessage( “initSetPlayerName”, “Player 1”);

Any other ideas for how I could further debug this?

Regards,

Olli

Ok it seems to be because I am using SendMessage in the onload method, so I assume the reason is because Unity has not been fully loaded yet.

Does anyone know how I could detect that Unity is loaded? Is there something in the Unity object for that?

Regards,

Olli

Hi!
Your best bet is probably to have unity call the external javascript function whenever Unity is ready for example in Awake():

pseudo code below;
Awake
if (Application.isEditor) {
initSetPlayerName (editorplayer);
} else {
Application.ExternalCall (“yourfunction”);
}
}
function yourfunction()
GetUnity().SendMessage(“3rd Person Controller”, “initSetPlayerName”, “Player 1”);

OK?

Yes of course, how did I not think of that.

Works great. Thanks for your help!

Olli