Search Unity

Question Button Click though

Discussion in 'UI Toolkit' started by lorddanger, Mar 18, 2021.

  1. lorddanger

    lorddanger

    Joined:
    Aug 8, 2015
    Posts:
    103
    Hello,
    In Tool kit button works fine but unlike the normal UI button the click is not blocked by the button
    It interacts with the button and goes through it makes it difficult to add it in Point and Click games
     
  2. lang_fox

    lang_fox

    Joined:
    May 19, 2014
    Posts:
    13
  3. JuliaP_Unity

    JuliaP_Unity

    Unity Technologies

    Joined:
    Mar 26, 2020
    Posts:
    700
    Hello! The behavior you're describing has been fixed already, it's just not out with the package yet (it requires Unity 2021.1). If you use UI Toolkit directly from your Unity installation on 2021.2 you should see that clicks don't go through there either.

    Hope this helps!
     
    lorddanger likes this.
  4. lang_fox

    lang_fox

    Joined:
    May 19, 2014
    Posts:
    13
    Looks like it doesn't work on 2021.2.0b4 ?
     
  5. JuliaP_Unity

    JuliaP_Unity

    Unity Technologies

    Joined:
    Mar 26, 2020
    Posts:
    700
    If you found a bug we encourage you to report it through the menu Help > Report a Bug
     
  6. achimmihca

    achimmihca

    Joined:
    Feb 13, 2016
    Posts:
    282
    Whether the ClickEvent is triggered on a VisualElement that is rendered below depends on their hierarchy.

    I found that all parents elements also trigger the ClickEvent. So if you want a parent NOT to receive this event, restructure your UI such that the element is not a parent anymore.

    Case 1:
    CommonParent
    |_OuterButton
    |_InnerButton

    In this case, a ClickEvent on InnerButton will also trigger the ClickEvent on OuterButton because the event is propagated upwards. Similarly, hover and focus states of USS are propagated upwards. This means OuterButton is hovered if InnerButton is hovered.

    Case 2:
    CommonParent
    |_OuterButton
    |_InnerButton

    In this case a ClickEvent on InnerButton will not trigger OuterButton. The buttons are siblings such that the propagated event will not pass OuterButton.
    Of course the layout now needs to be different. For my case, I can use absolute positioning for InnerButton to get the same visual layout as in case 1.

    Hope that helps.