Forum rules - please read before posting.

Question about menu button animation

Hello.
Sorry for my english

I have a question about the animation of menu buttons.
I have a Unity UI Based menu. When i click on one of the two buttons, the menu closes and opens again with new variables. In the Button component of both buttons, "Transition - Animation" and "Navigation - None" are set.

For some reason, if you do not move the cursor after clicking on one of the buttons, then after the menu reappears, the button does not highlight when the cursor is on it. In order for the Highlighted State to work in the animator, you need to remove the cursor from the button and hover again.

Is there a way to solve this problem?
Thanks.

Comments

  • UPDATE: The problem occurs only if "Transition type: Custom Animation" is set in the menu properties

  • What are your AC/Unity versions, and what properties are you animating in the Menu's transition animation?

    This may involve Unity's EventSystem. Look for it in the Hierarchy at runtime, and keep it selected. At the bottom of its Inspector, it'll display the currently-selected Button - click the horizontal panel at the very bottom if it's not showing.

    It should list the Button as selected before you click it. Keeping an eye on it while the issue occurs, what does it change to - both during the transition and after?

  • Thanks for the quick response.

    What are your AC/Unity versions

    Unity: 2020.3.30f1
    AC: v1.75.3

    what properties are you animating in the Menu's transition animation?

    Button Image Color and Text Color

    what does it change to - both during the transition and after?

    The cursor is on the button and it is highlighted correctly.
    https://disk.yandex.ru/i/kHfv_vsq6_6NPQ

    The cursor is on the button after the menu disappears and reappears, and it is not highlighted.
    https://disk.yandex.ru/i/O5vwaZtdFHOzOA

    If the cursor is removed and returned to the button again, it will be highlighted correctly.

    Thx.

  • Thanks for the details.

    Button Image Color and Text Color

    To be clear: this is for the Menu's transition animation, not the Button's, which is also animated through its own Inspector?

    I can attempt a recreation, but your setup sounds very specific. If possible, it would be best if you can PM me a .unitypackage of the files involved. From what you've described, the Menu Manager, UI prefab, the Button's ActionList, Animator controller(s) and Animation Clip assets should be enough.

  • To be clear: this is for the Menu's transition animation, not the Button's, which is also animated through its own Inspector?

    You're right. I have inattentively read your question.
    For the menu, these will be Canvas Group Alpha and Interactable.

    I have sent the necessary files to you in private messages.
    Thank you very much.

  • Thanks for the files.

    So far as I can tell, it does indeed look to be down to the way Unity's EventSystem behaves.

    The best workaround I can currently think of is to force the selection of Buttons when the mouse is over them. A Button's Selected state is separate from its Hover state, but it's not possible to enforce a Hover state through script - while Selected is.

    If you update your Button's Animator to have its "Selected" state play its "Hover" animation, you can place the following script in your scene to have the cursor automatically select Buttons as it hovers over them:

    using System.Collections.Generic;
    using UnityEngine;
    using UnityEngine.UI;
    using UnityEngine.EventSystems;
    
    public class ForceSelect : MonoBehaviour
    {
    
        private void Update ()
        {
            PointerEventData pointerData = new PointerEventData (EventSystem.current)
            {
                pointerId = -1,
            };
    
            pointerData.position = Input.mousePosition;
    
            List<RaycastResult> results = new List<RaycastResult> ();
            EventSystem.current.RaycastAll (pointerData, results);
    
            if (results.Count > 0)
            {
                Selectable selectable = results[0].gameObject.GetComponent<Selectable> ();
                if (selectable == null && results[0].gameObject.transform.parent) selectable = results[0].gameObject.transform.parent.GetComponent<Selectable> ();
                if (selectable)
                {
                    EventSystem.current.SetSelectedGameObject (selectable.gameObject);
                    return;
                }
            }
            EventSystem.current.SetSelectedGameObject (null);
        }
    
    }
    

    Separately: you don't need to have separate Animator Controller assets for each Button if the animations are the same. So long as each Button's structure/naming convention are consistent, you can re-use the same Controller.

  • Separately: you don't need to have separate Animator Controller assets for each Button if the animations are the same. So long as each Button's structure/naming convention are consistent, you can re-use the same Controller.

    Clear. Thanks.

    place the following script in your scene

    The script works fine. Thank you so much for your time.

Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Welcome to the official forum for Adventure Creator.