Bug?!?!

When my cursor is hovering over ‘InventorySlot’ it shows up tooltips BUT when cursor is moving on to hover over the icon which is over ‘InventoryItem’ image (In my opinion that image has another raycastable turn on which we need to dragging icon so can’t turn off) WHICH LEAD TO the problem because once the cursor detect new raycast the method ‘OnPointerExit’ is being called under ‘TooltipSpawner.cs’ class that’s why tooltips get remomved for me!

I really have no ideas why others don’t have this issue like I do?! Here are the images that show the problem.



It won’t capture my cursor in image so I draw where it would be as black cursor. Anyways I didn’t modify any source code yet this bug just came along when import the package.

Please, anyone? @Brian_Trotter

After debugging I’m did added a line of code the clear ‘tooltip’ cache under ‘TooltipSpawner.cs’ class.

Is this the proper way to do? Or am I missing something because others are not need to add like this??!

There is a bug in some of the 2021 versions of Unity which cause OnPointerExit to be called erroneusly. There’s another topic hiding out there with the fix, and I’ll link to it when I get home from work.

Hmm… I can’t seem to find the thread where this bug was discussed, but it seems to affect users in Unity 2021.1+…

What’s happening is that Unity appears to be invoking an exit when the cursor leaves the frame and goes over the item image, even though it should technically be within the tooltip region. This behavior changed from previous versions of Unity that would not invoke the PointerExit until the cursor has left the rect.

The fix for this is in the IPointerExitHandler in the TooltipSpawner script:

        void IPointerExitHandler.OnPointerExit(PointerEventData eventData)
        {
            var slotCorners = new Vector3[4];
            GetComponent<RectTransform>().GetWorldCorners(slotCorners);
            Rect rect = new Rect(slotCorners[0], slotCorners[2] - slotCorners[0]);
            if (rect.Contains(eventData.position)) return;
            ClearTooltip();
        }

What this does is check to see if the cursor is still within the actual rect of the image, ignoring the exit if the mouse is still inbounds. So when Unity puts up an OnPointerExit as you move further into the image, it’s simply ignored completely until an OnPointerExit is outside of the bounds.

3 Likes

Thanks a lot Brian! This code works great!

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms