BroadcastMessage has no receiver: should I care?

Hi! I have a button, it broadcasts messages to its children, which the user can unparent. If the user is a bit silly, he might hit the button whilst there are no objects to receive the message. Should I prevent the broadcasting if there’s no one on the receiving end, or just leave it at that? In other words, check for receivers every time the button is presse,d or allow a useless BroadCastMessage?

Thanks for your advice!


If you look closely at the documentation, you'll notice there's a third parameter, which is a SendMessageOptions argument.

The default value is SendOptions.RequireReceiver, which, according to the documentation, will print an error message if the message is not received by any component.

If you set it to SendOptions.DontRequireReceiver, the error message will not be printed.

I believe the downside to using BroadcastMessage is that it will operate on all children, which may not be super efficient. It probably doesn't matter unless you're doing it every frame.

If the object has no children (or a small number of children) the impact should be nothing (or almost nothing).