Search Unity

Question Event Trigger Select does not trigger from code

Discussion in 'UGUI & TextMesh Pro' started by vagelis199, Jun 9, 2023.

  1. vagelis199

    vagelis199

    Joined:
    Jul 27, 2012
    Posts:
    183
    I have a UI button and I added an Event Trigger from the inspector, with a Select option, the Select option calls a function from a script. The function gets called normally when the button is selected via navigation keys (keyboard/gamepad, whatever is assigned on Standalone Input Module to navigate) The problem lies when I try to select the button using EventSystem.current.SetSelectedGameObject() from a script in Update, I also tried Button.select() i get the same result, I know the button is selected because when I press the submit key the button gets submitted and a function gets called which is assigned for onClick, but the Event Trigger I added does not call the function assigned in Select. unless I press any navigation buttons, neither the selection animation of the buttons gets triggered, neither the Event Trigger Select in the inspector gets triggered, Why does this happen? and how can I solve it?

    Unity 2022.2.19
     
    dariakus likes this.
  2. dariakus

    dariakus

    Joined:
    Jul 22, 2021
    Posts:
    1
    I am running into this exact issue today. I have several functions registered to the Select() button in the inspector, and if I navigate to the buttons with the controller they work as expected.

    when I try to set one via code with button.Select() however, the button does become selected—highlight state turns on and if I click the A button it works—but none of the functions registered to Select() in the inspector work.

    Unity 2023.2.7
     
    Last edited: Mar 27, 2024