How to create button with irregular sprite shape?

Now i can change sprite for button background,but how do i change mouse event shape also?

In ugui i can use alphaHitTestMinimumThreshold to achieve.

Hi, this is not supported at the moment.

1 Like

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.

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.

This feature is not supported. Do you mean that we should explicitly document it “as not supported” in the documentation?

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?

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).

1 Like