Hi, I have a funny problem I can’t seem to wrap my head around.
I have two panels that swap when the mouse enters the standard one (1st), opening a second one (on top of the first one, that temporarily disappears), and when the mouse leaves the second one, the first standard one is restored).
This is the basic state (1st) of the panel
and here’s the second one once the mouse has entered the first one
If i leave the panel, the first one is restored correctly. My problem comes from those interactable buttons with plus and minus. The moment I enter them, OnPointerExit fires on the 2nd panel, and it flickers endlessly at that point (as it keeps on swapping panels and having OnPointerEnter and OnPointerExit).
As OnPointerExit fires before OnPointerEnter I noticed, I can’t even really add a “guard” of the sort “isOnButton” because that guard activates after the OnPointerExit has been called.
Is there a known way around this possibly without using coroutines and delays, that are too prone to issues in these cases?
I’m guessing the OnPointerExit is fired because your pointer is leaving the BG of the 2nd panel (in order to enter the button)?
A hotfix could be to add an update-method to directly check your pointer-position against the rect of your panel, then enabling/disabling the script (and thus the update-method) using the OnPointerEnter
you gave me a good idea, it worked even though slightly different. Basically when i “exit” the 2nd panel, i check if i am still inside its rect area or not, if i am, i am over a button, so i don’t have ti swap.
public void OnPointerExit(PointerEventData eventData)
{
if (IsMouseOver(eventData) == false)
{
_bagScript.ToggleCollider(_type);
_bagScript.ResetPanels();
}
}
public bool IsMouseOver(PointerEventData eventData)
{
return RectTransformUtility.RectangleContainsScreenPoint(_thisRectTransform, eventData.position);
}