Before updating to Windows 10 you may need to return your Pro license. More information here

problem with Unity.SendMessage !!!

Hi I wonder why it failed, I'm simply calling the player through a js function, but not working, there are requirements or anything special to prevent this from happening. Someone told me it was because I was trying to call an object that was already the son of a son of a son, and put it in the root of the inheritance, but does not work, js function works even before making the SendMessage, please help thanks .


// get unity

 function getUniytPlayer()
    var unity = unityObject.getObjectById("unityPlayer");
    return unity;
 //send msg to the browser
 function test(str)

 // data from flash
 function sendSkillsInfo(maxSkills,skillsSlots)
 var slots = new Array();
 var slotsData = String(skillsSlots); 
 slots = slotsData.split('-');
 alert(maxSkills + " : " + skillsSlots); // 1 : image.jpg
     the script does not work here 
 alert("Work it");

// C# using UnityEngine; using System.Collections;

public class SkillsManager : MonoBehaviour {

 // Use this for initialization
 public void assignskills()
     Application.ExternalCall("test","Unity !!!!");


more ▼

asked Sep 06, 2011 at 04:28 PM

avatar image

82 124 98 100

(comments are locked)
10|3000 characters needed characters left

2 answers: sort voted first

I think this line:


should be:


I'm not positive, just going off the documentation here.

more ▼

answered Sep 06, 2011 at 04:45 PM

avatar image

206 2 4 4

You are looking off of the wrong documentation. That is for GameObject.SendMessage and not Unity Player's SendMessage function. They are similar, but not the same. What you are looking for is here:


Unity Player's SendMessage needs both parameters, the first is the name of the GameObject, the second is the function name. It also has an optional 3rd paramater for passing a string to the receiving function. Essentially what it is doing when you call Unity.SendMessage("gameobject","function") is it does an internal GameObject.Find("gameobject").SendMessage("function");

Sep 06, 2011 at 05:03 PM equalsequals

Ah ok, so we can assume that he has a GameObject in his scene somewhere named GameManager, with the component SkillsManager on it. Got it.

Sep 06, 2011 at 05:08 PM Sigil

Correct. To iterate, say he has 2 components applied to this GameObject that both have a function "assignskills", calling the above function will result in both those components calling their "assignskills" function.

Sep 06, 2011 at 05:48 PM equalsequals

Thanks, other question, can I pass to a string Array? how can I?

Sep 06, 2011 at 07:09 PM juliancruz87

No, you can not pass an array of strings, only a single string.

Sep 06, 2011 at 07:45 PM equalsequals
(comments are locked)
10|3000 characters needed characters left

Unity has a problem with Unity.SendMessage seeing C#, if you were to convert your C# to a Unity JS class it would probably work.

Not sure why, it is possible that it may be something in the compilation order. In any case, any time you expect to receive Browser JS calls to Unity, the receiving class should be a JS class and not C#.



more ▼

answered Sep 06, 2011 at 04:57 PM

avatar image

5.4k 32 55 112

(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



Answers and Comments



asked: Sep 06, 2011 at 04:28 PM

Seen: 5116 times

Last Updated: Sep 06, 2011 at 07:46 PM