Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Clarification on GameObject.BroadcastMessage()

Discussion in 'Scripting' started by Jonathan Czeck, Jul 14, 2005.

  1. Jonathan Czeck

    Jonathan Czeck

    Joined:
    Mar 17, 2005
    Posts:
    1,713
    I guess I could check myself, but I thought it may be useful here. The message broadcasting is not recursive, right? It'll only send it to the immediate children?

    -Jon
     
  2. NicholasFrancis

    NicholasFrancis

    Joined:
    Apr 8, 2005
    Posts:
    1,587
    BroadcastMessage sends to children as well as the object itself. That is the object, all children, all their children etc...

    SendMessages send only to the game object it is called on.

    Be aware that you will get a warning message if nobody responds to the message. This is mainly for optimization purposes - you can use the optional flag SendMessageOption.DontRequireReceiver to get rid of it.
     
  3. Jonathan Czeck

    Jonathan Czeck

    Joined:
    Mar 17, 2005
    Posts:
    1,713
    Okay, sounds good. That's what I thought it *should* be. Was gonna file a feature request if it wasn't like that. :)

    Anyways, maybe make the documentation more clear on this subject?

    "Calls the method named methodName on every MonoBehaviour in this game object or any of its children."

    To me, children imply the "direct" children, not grandchildren or whatever.

    Cheers,
    -Jon