- Home /
How do I send an event to a target and all of its children?
I created a custom event type that I intend to use to inform my controller input that the user is interacting with the UI, and not to process input.
public interface IProcessInputHandler : IEventSystemHandler {
void OnDisableInput();
void OnEnableInput();
}
I applied this to a script that is a component of a GameObject. This GameObject has a child object that is the player camera. This player camera also has a MonoBehaviour script that inherits this same interface.
public class Player : MonoBehaviour, IProcessInputHandler {
//Implemented.
}
public class PlayerCamera: MonoBehaviour, IProcessInputHandler {
//Implemented.
}
I used the static helper class ExecuteEvents to execute the event in the EventSystem:
ExecuteEvents.Execute<IProcessInputHandler>(player, null, (x, y) => x.OnDisableInput());
As expected, this gets called on the Player GameObject just fine. It doesn't get called on the child GameObject PlayerCamera.
The manual suggested that there was a static function on the helper that could do this.
I only found ExecuteHierarchy which executes up the hierarchy. Sure, I could execute from PlayerCamera up to Player, but that's not the behavior I want. I want to execute to Player, then to Player's children.
Is my only option to use SendMessage, or am I just not using the EventSystem correctly?
Your answer

Follow this Question
Related Questions
How to let handled events / raycasts pass through 1 Answer
EventSystem - all touches have the same ID 3 Answers
EventSystem.current is returning null 9 Answers
Android Touch Issue(2 buttons) 0 Answers