SendMessage to all gameObject children

Hi!

There is a SendMessageUpwards function, which sends message to all gameObjects in upper heirarchy, but i wonder is there SendMessageDownwards? It seems that there is none.

I just need to Send a message to all gameObject children not requiring receiver…

Also what is the difference between BroadcastMessage and SendMessage?

Thanks in advance!

I too would like a SendMessageDownwards or SendMessageToChilren function. I'm afraid to use Broadcast because if it sends the message back to its self it will likely cause an infinite loop for what I'm trying to do. I can kludge it or work around it in many different ways, but if someone knows a simple efficient way of doing it I would be grateful to whoever could share it.

2 Answers

2

The docs clearly explain what the difference is; e.g. for BroadcastMessage: “Calls the method named methodName on every MonoBehaviour in this game object or any of its children.” As opposed to SendMessage: “Calls the method named methodName on every MonoBehaviour in this game object.” So that should answer the first question.

Thanks, didnt get it...

@G_Sacristan: to clarify the answer: use BroadcastMessage.
It will send the message to all contained objects.

SendMessage does not traverse the hierarchy