- Home /
BroadcastMessage
I want to use a SendMessage(), BroadcastMessage(), etc. to call any function I name on: a) the game object, b) all its children, c) all its parents. Is BroadcastMessage() the right function for this? Or should I write my own that calls SendMessage(), SendMessageUpwards(), SendMessageDownwards()?
Answer by Adam Rademacher · Nov 12, 2010 at 12:47 AM
SendMessage will call the functions on any script attached to the recipient gameobject.
BroadcastMessage will call the functions on any script attached to the recipient gameobject or its children.
SendMessageUpwards will call the functions on any script attached to the recipient gameobject and any script attached to a gameobject that is an ancestor (parent, parent's parent, parent's parent's parent, etc.).
Edit:
You will have a tough time doing this because sending more than one type of message will cause the recipient gameobject to call the function more often than it should. You might want to use transform.parent or transform.root and then broadcast from there unless you know that there will be branching paths that shouldn't get the message.