- Home /
How to detect which UI Button was triggered via Script (and not actually clicked)?
I want to trigger UI Buttons with a Joypad. Those Buttons all trigger the same function and this function is checking which Button was clicked with the "EventSystem.current.currentSelectedGameObject". (Works fine when actually clicked in the UI itself.) In the update function I check if a certain Joypad-Button was pressed and then I want to trigger the UI Button via Script with "Button.onClick.Invoke()".
The main problem I am struggling with here: EventSystem.current.currentSelectedGameObject does not seem to work appropriate together with the Button.onClick.Invoke(), as I get a NullReferenceException. I guess because the currentSelectedGameObject is null and is not receiving the actual Button reference via Invoke().
Anyone has an idea or workarounds how to trigger Buttons via script and then get its reference?
Thanks!