I’m trying to figure out how to programmatically set a button to “selected”, it has proven to be harder than expected. Or at least, not very obvious.
I am currently calling eventSystem.SetSelectedGameObject.
For the arguments, I am giving it
my GameObject with the Button component,
new BaseEventData(eventSystem)
It seems to work, but feels unusual that i have to pass this second argument though. Is this right?
Are there any videos or tutorials anywhere that explain the “Selectable” stuff, and UI navigation? I saw this video, which explained a bit about the event system. Otherwise the docs that shipped with 4.6 are kind of light on this new UI navigation stuff. Or, I missed it.
I am just solving same thing. Why I have to change selected UI by code? Some type of drag and drop solution could be better. I pass as second argument null
Of course, but I think change focus when I go to another menu. From Main menu to Options for example. I know that it is super simple script, but integrating this function could be better
Yeah, the docs are light on the user interface navigation info.
I think it makes sense to NOT automatically select user interface objects, though. Otherwise you would have to write lots of annoying code to deselect things (if the behavior was not what you wanted.)
I’ve been playing around with this, I have my main menu and then I select options and I make the options canvas active.
(I’m using a gamepad controller btw)
I use this script as a component in my button:
public void Select(GameObject selection)
{
eventSystem.SetSelectedGameObject(selection, baseEventData);
}
then I call this from the button On Click () in the inspector.
What happens is that it select the new object but the old object stays selected forever and ever…