UI question: Easy way to call a function on every Button OnClick?

I’m a few months into development on a project, and I have a couple dozens GameObjects, and probably hundreds of different buttons inside these prefabs. I want to capture an analytics event where the button clicked gets logged somewhere, but I want this to happen for every single button clicked. I didn’t want to go through every prefab, one by one, and add a separate component to its button on click; that seems excessive, and also like a waste of memory.

Is there an easy way to globally call a specific function for each Button when its OnClick is called, and have it pass the button’s gameobject itself as a parameter to that function? I’m trying to mess around with the Standalone Input Module, but some buttons, when clicked, destroy themselves, and these aren’t being captured via MouseButtonUp() (maybe because it gets destroyed before MouseButtonUp() detects the object? Not sure).

Dunno off-hand what the best way is to shoe-horn that code in this far along.
However, there is multi-selection/editing in the editor. If you add all of your game objects to the scene, you can select & modify every button so their OnClick event points to some gameobject, and then some script-> a method :slight_smile: