I have a simple menu with a question and two answers represented by two buttons. The two buttons are animated, so I set the transition type to “Animation”. On the first button I added a script that does “GetComponent().Select()” in OnEnable() so that button is selected directly when the menu appears (it is not the first menu so I can’t use the first selected value of EventSystem)
My problem is : the button is indeed selected (if I press the submit button, everything in OnClick() is called) but the state is set to normal instead of highlighted. If I move right, the second button gets highlighted, if I move left, the first button gets highlighted as it should have been from the start.
How can I force the first button to be selected ? Isn’t that the purpose of the Select() method ?
Also, if I press submit with the button not highlighted (only selected), OnClick() is called but nor Disabled nor Pressed are sent to the animator.
Is this a bug in unity ?
Lastly, Idle and Active are animations with 0 length and transitions of 0.1 seconds, still, I can’t quickly change from one button to the other, often, it will take more than one second before the joystick movement is registered.
BTW: I use a custom input module which is the standalone input module with everything mouse related removed.
I found a crappy solution. But first some background : so if you use the generated controller, everything works as it should. The problem here is that I had a “open” animation played before any other. For some reason, even if I set the open->idle transition to be on the condition of “normal” to be triggered, the transition is taken but the normal trigger isn’t reset.
The solution : start the animator, wait a bit, enable the button.
Still feels like a bug in unity, if someone could explain what really is going on, I would be very interested.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class FirstButton : MonoBehaviour
{
Button button;
// Start is called before the first frame update
void Start()
{
button = GetComponent<Button>();
button.Select();
}
}