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

Disable UI Button vs <image> component

Discussion in 'Immediate Mode GUI (IMGUI)' started by Trav3l3r, Sep 16, 2014.

  1. Trav3l3r

    Trav3l3r

    Joined:
    Sep 16, 2014
    Posts:
    60
    Hi,

    I 'd like to use a UI button where the visual component is not active during runtime. My first guess was to disable the <Image> component of the button, but then I suddenly also lose the onclick events.

    Two questions:
    1) How can I disable the renderer? (I noticed setting the alpha to zero is an option, but that seems very inefficient)
    2) Why are button events depended on the Image component and for example not on the Button script, which seems more logical?


    Thanks in advance

    PS i'm using 4.6.0b17
     
  2. secondbreakfast

    secondbreakfast

    Joined:
    Jan 5, 2013
    Posts:
    98
    If you want to make the button still clickable, but not visible, adjusting the alpha on the image is the right way to go.If you don't want the button to work, set the active value on the game object. The event system needs an implementation of Graphic in order to send events. That's just how it was designed. I think the reason is because it may have a non rectangular shape and if you send all recttransform events to the button script, it will then need code to filter out events and now the button script would depend on mask, image, etc... Instead they made it easy for the script implementer to always respond to the events and they can be sure it was a proper click. You might also be able to implement your own Graphic and use that instead of Image if it bothers you using the alpha.
     
    Last edited: Sep 16, 2014
  3. Trav3l3r

    Trav3l3r

    Joined:
    Sep 16, 2014
    Posts:
    60
    Thanks for your reply!

    If there's no other way then I'll stick with the alpha channel solution.

    Perhaps this is something to request as a feature...