Search Unity

button.interactable

Discussion in 'UGUI & TextMesh Pro' started by GameDevRick, Dec 11, 2017.

  1. GameDevRick

    GameDevRick

    Joined:
    Oct 8, 2011
    Posts:
    269
    In Unity 2017.2, I set a UI button to not interactable using the event triggers component.
    The button color changes as it is expected to, but the button is still clickable and the events fire.
    I checked all my parent panels for raycasting and disabled them. I just want the button to grey
    out and be un-clickable and I am setting the interactable bool to false to accomplish that. Is there
    something else that I need to do?
     
  2. methos5k

    methos5k

    Joined:
    Aug 3, 2015
    Posts:
    8,712
    I just did a small test of that , which also goes along with a question I was going to ask :)

    So, I tested a very simple scene where my button would disable a game object. when it's interactable is false, it doesn't work.
    I then added an event trigger and added onclick for the same thing, and now when interactable is false it will disable the game object. I figured code would still work.

    So I guess my question is: Do you have code or an event trigger on the button? :)
     
  3. GameDevRick

    GameDevRick

    Joined:
    Oct 8, 2011
    Posts:
    269
    I am using the built in event trigger on the button itself.
    Here is a screen of the button that makes the other buttons non-interactable:

    13795ea6c6ecbb3c7b8924eeabacb9ba.png

    And here is a screen of the Buy Healing button which becomes non-interactable but still remains clickable:

    7aec5f4a1e13ae352c8060d9d0aad776.png

    I suppose, I could try disabling the interactability of the button through code, but I think it should work as it is now
    and I am hoping someone can provide a bit if insight and/or a solution.
     
  4. methos5k

    methos5k

    Joined:
    Aug 3, 2015
    Posts:
    8,712
    Okay, perhaps you didn't understand what I wrote. In my test, with an event trigger, it's unaffected by the interactable of the button :)

    What you can do is disable raycast target on the button (and any child objects it may have, eg: default 'Text').
    I just tested and that works. This doesn't care whether the Button is interactable or not.
     
  5. GameDevRick

    GameDevRick

    Joined:
    Oct 8, 2011
    Posts:
    269
    Yes sir, that worked well.. thank you for helping.

    Well... that worked for one of my menus but not for another.
    Despite having both interactability set to false and also raycast target set to false on the image,
    the button still works and the events fire.

    After re-reading what you wrote, you made me realize that the child object with a text component on it also had raycasting enabled. After disabling those, they work as they are expected to.
     
    Last edited: Dec 12, 2017
  6. methos5k

    methos5k

    Joined:
    Aug 3, 2015
    Posts:
    8,712
    Nice :) Glad you got it resolved n working.