Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Disabled button animation state not getting triggered

Discussion in 'UGUI & TextMesh Pro' started by adamt, Jan 11, 2017.

  1. adamt

    adamt

    Joined:
    Apr 1, 2014
    Posts:
    116
    EDIT: Ugh, of course it works just after I post a new thread. I'm not entirely sure what went wrong, but I think I had a keyframe that Unity had added that was transitioning my animation back to its "normal" state. Not knowing whether I'm looking at a keyframe or a unit of time underneath the red vertical bar in the Animation window has bitten me more than a few times, and it seems as though this might've been one of those times.

    I'm trying to use animation transitions for my buttons as opposed to color tints, to give my UI a bit more life. I have a shared animator between all my buttons for consistency that currently has a "Pressed" animation that simply scales down the button a bit and tints its attached image component. This process happens in reverse when the button is no longer pressed, which looks just fine. I'm using Unity's built-in animator for buttons, for reference.

    However, I now want to add a "Disabled" animation that simply sets a tint on the button's image component (this should happen immediately, and last indefinitely). This transition should fire when my button's interactable field is set. For whatever reason, this isn't happening. I've looked at the code for Selectable and it seems as though it should be happening, but for whatever reason my button does not tint when it's marked as non-interactable.

    At first I thought this was because I'm setting my button's interactable field in an attached script's Start method, which was muting any animation since it happens before the first frame (not sure if that's how it actually works, just speculation). But after setting the interactable field to false in the button's OnClick handler, the Disabled animation still does not fire, so I'm not sure what's going on. I also thought I might need to create a new transition between Pressed -> Disabled (since the default button animator only has Pressed -> Normal), but this shouldn't apply to buttons whose interactable field are set solely through code during script initialization.

    I feel like I'm missing something simple here. Hopefully someone can shed some light on the situation.
     
    Last edited: Jan 11, 2017
  2. Nicolas_nvizzio

    Nicolas_nvizzio

    Joined:
    Jun 27, 2017
    Posts:
    1
    I have the same animation on my buttons, one that is affecting the scale and/or color of the button. I got the same issue as well.
    I found that it was caused by calling button.interactable = false; before calling button.gameObject.SetActive(true); I reversed the two calls and it works now.
    Prior to that I had found that all 4 states (normal, highlight, pressed, disabled) of the animation needs to define both color and scale values even if only one is animated. Otherwise you may end up with strange behaviors when the button is turned active/inactive in the middle of a transition.