- Home /
OnPointerExit Not Being Triggered
I'm creating a tooltip system for my inventory using the UI features in Unity, however, I've found that OnPointerExit is never being called. OnPointerEnter and Down both work fine, it's just Exit that doesn't and I don't understand why. If none of them worked it would at least make more sense. Any help would be greatly appreciated.
Inventory Slot:
public void OnPointerEnter(PointerEventData ped)
{
if(inv.items[slotNumber].itemName != null)
{
inv.ShowTooltip(inv.slots[slotNumber].GetComponent<RectTransform>().localPosition, inv.items[slotNumber]);
}
}
public void OnPointerExit(PointerEventData ped)
{
Debug.Log ("Pointer Exited Slot.");
inv.HideTooltip();
}
Inventory:
public void ShowTooltip(Vector3 tooltipPos, Item item)
{
if(item.itemType == Item.ItemType.Consumable)
{
consumableTooltip.SetActive(true);
}
}
public void HideTooltip()
{
Debug.Log ("Hiding Tooltip.");
consumableTooltip.SetActive(false);
}
Do you try to call OnPointerExit at the same place you call OnPointerEnter ? I had troubles once because I hade a panel that was below in the hierarchy (and so on the upper layer) and I was entering my panel by the top (where there was only one layer) and exiting by the bottom (where there was two layers and the one with the event was not the top one)
This is what the hierarchy looks like. The highlighted part (Slot) is where the Script which has OnPointEnter and Exit is.
Answer by Abysinian · Apr 02, 2015 at 05:50 PM
Problem solved. I had been following a tutorial to help with this and it failed to mention that I needed to add IPointerExitHandler to my class declaration:
public class InventorySlot : MonoBehaviour, IPointerDownHandler, IPointerEnterHandler, IPointerExitHandler
Your answer
Follow this Question
Related Questions
New UI Is active but not drawing 0 Answers
Fading Out UI On Play 1 Answer
Unity UI not showing some Images 0 Answers
UI- Rotational Inventory,Where to begin? 2 Answers
One button doesn't cycle through an array when pressed. 1 Answer