EventSystem: how to highlight instantiated button?

Hi everyone.

I’ve structured a Dialogue System that will allow the player to respond NPC’s by selecting between multiple answers, thus allowing for branching narratives.
The answers the player can choose are instantiated GameObjects UI with a button attached to them that are generated from a list, and the player can navigate the answers using horizontal movement (Keyboard or Gamepad). The player can have a single or multiple answers to choose from, as the system is quite dynamic.

Overall it works well, but I’m stuck with an issue as I can’t seem to find a way to highlight the first Gameobject to guide the Player in choosing an answer. Basically what happens is this: the player advance with the dialogue, then a response (or more than one) appear: none of them is selected/highlighted (Ive tried EventSystem.current.SetSelectedGameObject(button);).

The responses gets highlighted only if there are more than one, and only when the player uses the gamepad or keyboard to navigate them (in which case, the selected GameObject is always the last one).

Thanks in advance for your time and answers.

Hey,

Are you generating the GameObject prefab from a list or array? If so could you utilise the Buttons ‘tabIndex’ and / or ‘spriteState’ on object [0]?