Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Question How to create button with irregular sprite shape?

Discussion in 'UI Toolkit' started by ununion, May 16, 2022.

  1. ununion

    ununion

    Joined:
    Dec 2, 2018
    Posts:
    268
    Now i can change sprite for button background,but how do i change mouse event shape also?
     
  2. ununion

    ununion

    Joined:
    Dec 2, 2018
    Posts:
    268
    In ugui i can use alphaHitTestMinimumThreshold to achieve.
     
  3. antoine-unity

    antoine-unity

    Unity Technologies

    Joined:
    Sep 10, 2015
    Posts:
    733
    Hi, this is not supported at the moment.
     
    ununion likes this.
  4. antoine-unity

    antoine-unity

    Unity Technologies

    Joined:
    Sep 10, 2015
    Posts:
    733
    Thinking about it some more, it's probably feasible if you create (derive) a custom Button and override the ContainsPoint method. You could check the texture's alpha channel based on the specified point given to this method.
     
  5. Halquigo

    Halquigo

    Joined:
    Mar 29, 2017
    Posts:
    6
    Oh!
    Would you please confirm this?
    'Coz I found that this feature is not working correctly on a recent build with Unity 2022.1.21f1.
    But I cannot find any official notice about this at the release notes or documents.
    Thank you in advance.
     
  6. antoine-unity

    antoine-unity

    Unity Technologies

    Joined:
    Sep 10, 2015
    Posts:
    733
    This feature is not supported. Do you mean that we should explicitly document it "as not supported" in the documentation?
     
    Last edited: Nov 7, 2022
  7. Halquigo

    Halquigo

    Joined:
    Mar 29, 2017
    Posts:
    6
    Oh, maybe there's a mis-understanding between us.

    The alphaHitTestMinimumThreshold worked fine on my app built with Unity 2021.1.28f1.
    But it's not working correctly with Unity 2022.1.21f1.

    I thought you meant that alphaHitTestMinimumThreshold is no longer used.

    What am I missing?
     
  8. antoine-unity

    antoine-unity

    Unity Technologies

    Joined:
    Sep 10, 2015
    Posts:
    733
    I think the misunderstanding is that I am talking about UI Toolkit (where it's not supported). If you are already using featur successfully in 2021, it means you're using UGUI / Canvas (where it is supported).

    So it doesn't work for you in 2022 it is a bug and I'd recommend you report it as such (in Unity, Help > Report a Bug).
     
    Halquigo likes this.