Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.

Question How to update dynamically the UI button used with ''On Select''?

Discussion in 'Visual Scripting' started by Marou1, Aug 20, 2022.

  1. Marou1


    Dec 13, 2021

    I have a script with an empty variable ''Child2''. On Start, I assign a game object to the variable ''Child2''.
    The assigned game object is a UI button.

    The script defines some actions when the button contained in the variable ''Child2'' is selected (On select event).
    But even though I assigned On Start the button to ''Child2'', the On Select Event keeps considering ''Child2'' as empty.
    If I use the debug, it confirms that ''Child2'' was updated, but not with On Select Event. Please see the screenshot.
    1- Is this the expected behaviour?
    2- If yes, why was it designed that way?
    3- How can I change the content of Child2 and have On Select event take it into account? The reason I need this is that I want to use the same script for many different objects and I don't want to hardcode the value of Child2, Instead, Child2 will contain the child with the index2 of the game object the script is assign to.

    Last edited: Aug 20, 2022