[SOLVED] What's is the difference between these functions?

Component.SendMessage
GameObject.SendMessage
Component.BroadcastMessage
GameObject.BroadcastMessage

They all seem similar from reading the API.

One need to get the “gameObject” active and the other must have the component active.

OK but what about between send and broadcast?

It doesn’t give a … if the gameObject / component is active ? :stuck_out_tongue:

(I’m not sure but this is the only difference SendMessage and BroadcastMessage)

No. The explanation in the docs is quite straightforward:

Unity - Scripting API: Component.SendMessage “Calls the method named methodName on every MonoBehaviour in this game object.”

Unity - Scripting API: Component.BroadcastMessage “Calls the method named methodName on every MonoBehaviour in this game object or any of its children.”

–Eric

2 Likes

Thanks I missed that last part.

Just for clarification there is no difference between Component.SendMessage and GameObject.SendMessage. Use which ever one is most convenient in your code.

Component.SendMessage is the same as Component.gameObject.SendMessage.