- Home /
BroadcastMessage between children?
If I have a hierarchy:
-Parent
--ChildOne
--ChildTwo 
Can ChildTwo have a BroadcastMessage on it that ChildOne can "hear"?
Answer by zachypin · Jun 30, 2011 at 06:59 PM
The answer is yes, but you have to reference that child.
 var target : GameObject;
 
 function Start()
 {
     target.BroadcastMessage("ClassToCall");
 }
Answer by PrimeDerektive · Jun 30, 2011 at 08:36 PM
Yes, it's called SendMessageUpwards() :)
EDIT: Or did you mean laterally (eg: a child on the same level of the hierarchy?) Because BroadcastMessage should do that by default.
Answer by Molix · Jun 30, 2011 at 07:00 PM
Depending on your other requirements, you could send the message from ChildOne's parent, or even its root (in case the hierarchy was many layers deep). e.g.
 childOne.transform.parent.BroadcastMessage(...);
or
 childOne.transform.root.BroadcastMessage(...);
The 'root' of a hierarchy is the object without a parent. In your example "Parent" is also the root. If "Parent" had its own parent, say, "Grandparent", then "Grandparent" would be the root.
See http://unity3d.com/support/documentation/ScriptReference/Transform-root.html
Your answer
 
 
              koobas.hobune.stream
koobas.hobune.stream 
                       
                
                       
			     
			 
                