EventSystem "SendMessageUpwards" Replacement

Is there a way to send a message to a gameobject and ALL it’s children? ExecuteHierarchy seems to stop sending when the first handler is found. I’m basically looking for a replacement to “SendMessageUpwards” and I don’t want to keep track of all the handlers myself.

Not really.
This EventSystem is a whole manager in itself (like a singleton) to negotiate message exchange. It doesn’t know about the objects that are subscribed or notifying about messages.

If you want a child object to notify it’s parents, then either the old message system or a more OO approach would be better.

You don’t have to “manage” handlers as it is a weak reference system.

Hi pojoih, Can you give some more information about how exactly you want to use this. There are a number of different ways to solve the problem of sending messages between objects, but you’ll need to be more specific about the details of your setup to be able to help.

1 Like

I want to build a notifying system for components inside a player prefab hierarchy, eg. spawn/kill/hit/Targeted etc.and there are some requirements.

  • I don’t want to keep track of all the components myself as they change a lot during runtime

  • Ideally the events can be fired from one place, like a RPC/Command method in a NetworkBehaviour in the root gameObject as this is for a multiplayer game.

  • Messages must reach ALL components which are implementing the belonging interface, not just one.

I could iterate through the hierarchy tree of the object and fire a ExecuteEvent on every child myself, but I don’t know about the overhead so maybe some “ExecuteEventInChildren” function would be cool for such a case.

Until then seems I have to live with SendMessageUpwards or use the new messaging system and keep track of all the scripts on child objects which are implementing my own event interfaces.

Take a look at the ExecuteEvents class, something like ExecuteHierarchy should give you something you need with a few small changes.

oh man, totally forgot this thing is open source! My bad, thanks Karl.

1 Like