Button not interactable but still responding to events. How do you fix this?
I am trying to make a UI Button that the user can hold down as long as they want.
The OnClick() events don't work because it only triggers on a full down/up click, so I added a pointer down and pointer up events to start and stop the buttons functionality. Problem is now the button responds to events even when it has "interactable" set to "false."
I've seen about 4 different questions all being answered with "disable the 'Blocks Raycast'" parameter, however it seems that parameter no longer exists.
Thanks for your help!
Answer by Qhuhuit · Apr 18, 2021 at 09:43 AM
I had a similar problem @BlackOpsBen , button interactable property set to false, but still interactable.
Tried set the image target raycast property to false, didn't fix it.
Then added a Canvas Group component and set it's interactable and block raycasts properies to false, that's finally worked !
I don't understand why I had to do that, this clearly don't seems like the desired behaviour.
"so I added a pointer down and pointer up events to start and stop the buttons functionality" Button does not have OnPointerDown and OnPointerUp events. Have you written a script to listen to them? These events are invoked by the EventSystem, which will send to all MonoBehaviour assigned to a gameobject containing the raycastable component (Image, Text, etc.). So, you need to have a reference to Button and test the Button.interactable condition yourself to execute your custom code.
"Then added a Canvas Group component and set it's interactable and block raycasts properies to false, that's finally worked !" This works because you have blocked the raycast component, so no event will be sent.