broadcast message doesn`t do anything, no errors

I have used broadcast message in my game before and it works just as it should.

So I added a new one that works te same way as the rest, but this one doesn`t do anything.

Here is my code:

//This is the broadcast

GameObject Controller = GameObject.FindGameObjectWithTag("GameController");

                    Controller.BroadcastMessage(j.ActionMethod,float.Parse (p.ActionParameter));
//This is the receiver
function Bulletin (BulletStr : String) {
        ShowBullet = true;
        BulletString = BulletStr;
    }

//This is what it should do
function OnGUI(){
    if (ShowBullet)
    {
                GUI.BeginGroup (Rect (Screen.width / 2 - 264, Screen.height / 2 - 106, 528, 212));
                    GUI.DrawTexture(Rect(0,0,528,212), TextBlock);
                    GUI.TextArea(Rect (16+8, 16+24+32,480,96), BulletString);
                 
                    if (GUI.Button(Rect(8, 8+164, 512, 32),"I get it!"))
                    {
                        ShowBullet = false;
                    } 
                GUI.EndGroup ();
    }
}

I don`t get any error messages, the other broadcasts work the same way and they work fine.

Can anybody help me? It`s really frustrating.

This isn’t a fix, but a suggestion to help debug. Instead of:

Controller.BroadcastMessage(j.ActionMethod,float.Parse (p.ActionParameter));
var methodName = j.ActionMethod;
var parameter = float.Parse (p.ActionParameter);
Debug.Log("Broadcasting methodName: " + methodName + ", parameter: " + parameter);
Controller.BroadcastMessage(methodName,parameter);

Maybe there’s an error in the value of methodName.

Hi, thanks for your reply.

I tried your code but it didnt show me any mistakes. But i tried sending an integer as a parameter instead of a string, and it worked. I guess I cant send any strings with broadcast message. Perhaps you know why?

I maybe out of th subject, just in case, do you specifically want to use BroadcastMessage? Or any other way to speak to your function will match your needs?

no, broadcast message just seemed the most appropiate way to do it.

Okay, so let’s say the script where you have your function Bulletin on your GameController is called Reciever.js, so instead of:

GameObject Controller = GameObject.FindGameObjectWithTag(“GameController”); Controller.BroadcastMessage(j.ActionMethod,float.Parse (p.ActionParameter));

You could call your function like so:

GameObject.FindWithTag(“GameController”).GetComponent(Reciever).Bulletin(“The bullet message I want to send”);

okay, is it possible to do something like this?

GameObject.FindWithTag(“GameController”).GetComponent(Reciever).j.ActionMethod(float.Parse (p.ActionParameter));

because I want to be able to change the function in the inspector

That’s why I asked you if you wanted a specific way to do it. I couldn’t tell you I’ve never tried those ActionMethod things