Problem using OnPointerEnter() with a Horizontal Layout Group

Hi,

I am attempting to make an inventory tooltip for my game. The inventory uses a vertical layout group for its rows, and each row contains a horizontal layout group to align the individual item slots.

I am using the OnPointerEnter() function on each individual item slot, which should return true only when the mouse is hovering over that slot. For some reason, however, this is not the case. I have recorded a video to demonstrate:

The first slot should only show information for the Pistol, and the second the AK-47. Other slots should just return empty strings.

As the video demonstrates, the OnPointerEnter() function seems to disagree with where the mouse position is. Perhaps I have looked at this the wrong way?

I hope that a solution is possible, and thank you for taking your time to read this. My code, which is attached to each slot (white UI box), is as follows:
Code

using System;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.EventSystems;

public class InventorySlot : MonoBehaviour, IPointerEnterHandler, IPointerExitHandler
{

    public string itemName = "";
    public string itemDescription = "";
    public string itemSellValue = "";

    private bool mouseHovering = false;
    private Inventory inventory;
    private GameObject tooltip;

    void Start() {
        tooltip = GameObject.Find ("InventoryTooltip");
        if (tooltip == null) {
            inventory = GameObject.Find ("GameManager").GetComponent<Inventory> ();

            tooltip = Instantiate (inventory.inventoryTooltip) as GameObject;
            tooltip.name = ("InventoryTooltip");
            HideTooltip ();
        }
        tooltip.transform.SetParent(GameObject.Find("UI").transform);
    }

    public void OnPointerEnter(PointerEventData eventData)
    {
        UpdateTooltipText ();
        mouseHovering = true;
        print (gameObject.transform.name);
    }

    public void OnPointerExit(PointerEventData eventData)
    {
        mouseHovering = false;
        HideTooltip ();
    }

    void Update() {
        if(mouseHovering) {
            Vector3 position = new Vector3 (Input.mousePosition.x + 110f, Input.mousePosition.y - 50f, 0f);
            tooltip.transform.position = position;
        }
    }

    void HideTooltip() {
        tooltip.transform.position = new Vector3 (Screen.width * 2, Screen.height * 2, 0f);
    }

    void UpdateTooltipText() {
        tooltip.transform.Find ("Title").GetComponent<Text> ().text = itemName;
        tooltip.transform.Find ("Description").GetComponent<Text> ().text = itemDescription;
        tooltip.transform.Find ("Price").GetComponent<Text> ().text = itemSellValue;
    }
}

Best regards,
Rees.

@Rees_1

Hi there,

I tried your code… I don’t see it happening… seems to be working just fine, although I just used one tool tip that is already as child of canvas, and I assigned it to each slot’s tooltip variable.

Show and hide works just fine, showing one slot at time.

So maybe first try with simple setup, slots on canvas instead of as child of Layout Group…
maybe there is something else going on, that is not obvious from your code.