How do I force the SelectedObject when the user presses the select button on their gamepad?

For some reason when the user presses the select button to navigate our gui, an invisible button is selected first:

https://gyazo.com/694247223ff362af17d44c360445d049

The user can’t navigate back to that button once they navigate away as you’d expect, so it’s weird it’s what started selected in the first place.

There must be some way of detecting when the user presses select and then forcing the SelectedObject to be something sensible (like a visible shop button) but I’ve searched the api docs for half an hour now and I must be overlooking it.

2 Likes

I believe you’re looking for the Documentation - Roblox Creator Hub property in this case.

As for detecting when the user presses their Select button, there’s Documentation - Roblox Creator Hub to use, with the InputObject’s KeyCode being Enum.KeyCode.ButtonSelect.

As for preventing invisible buttons to be selectable, you should turn off their Documentation - Roblox Creator Hub property. :slight_smile:

2 Likes

The cleanest way to pull this off is to turn off AutoSelectGuiEnabled and then bind custom SelectedObject setter logic to the select button.

ContextActionService::BindAction(AtPriority) would probably be the most convenient way of doing the latter, otherwise listen to InputBegan as explained above.

2 Likes

Because I couldn’t believe that was the answer I tried an experiment and discovered that a button whose Selected property is set to true is what is selected when we press the select button!

So that’s easy.

1 Like