Can't get IPointer Enter/Exit to work on a Sprite with Collider

Hello.

Yesterday I changed from the old input system to the new one. In my game scene, everything works great, and I’m very happy.

But, it’s broken my Character Creation Screen.

I used to have two different types of Pointer/Mouse handlers for tooltips.

One for event Data (on UI elements)

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.EventSystems;

public class OnHoverMakeActiveUI : MonoBehaviour, IPointerEnterHandler, IPointerExitHandler
{
    [SerializeField]
    public GameObject _gameObjectToMakeActive;

    public void OnPointerEnter(PointerEventData eventData)
    {
        _gameObjectToMakeActive.SetActive(true);
    }
    public void OnPointerExit(PointerEventData eventData)
    {
        _gameObjectToMakeActive.SetActive(false);
    }
}

And one that used OnMouseEnter() (on things like sprites with a capsule Collider)

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.InputSystem;

public class OnHoverMakeActive : MonoBehaviour
{
    [SerializeField]
    public GameObject _gameObjectToMakeActive;
    public void OnMouseEnter()
    {
        _gameObjectToMakeActive.SetActive(true);
    }
    public void OnMouseExit()
    {
        _gameObjectToMakeActive.SetActive(false);
    }
}

I ported across to the new Input system, and bam, the second one didn’t work. After investigating, I found out this is a common issue, and OnMouseOver doesn’t work with the new Input system.

Never fear, I thought. I still have my other script I was using for UI elements, so I’ll just do that.
The suggestion Ive seen is to:

  1. make sure you have a 2D raycaster on your camera. I do
  2. make sure you have a InputSystemUIInputModule on your Event System. I do
  3. Collider on your GameObject (I do)
  • I already had a lot of these things set up because I had these two types of Hover scripts.

Anyway. Long story short, it isn’t working. Anyone know how I can get this functionality to work?
I know I could just convert my sprite to an image, or add a button, and the other script will work, but for a number of reasons, those two options weren’t very attractive.

You have two major ways to get “OnMouseOver”-ish thing to work:

  • Use “Both” InputSystem setting in your player, so the old system will fire the OnMouse* methods (I don’t really recommend it)
  • Put colliders on it and fire a raycast per frame or per every N frame (whatever your use case is) from the mouse position into the scene and check if you hit a thing you’re looking for. I recommend this, although obviously it’s not that lazy and simple like an OnMouseOver method on a MonoBehaviour, but it’s working exactly like that. You can do that from a manager-like class, so you aren’t raycasting from every object separately, but once and you can sort through the results in the method you use for raycasting.
1 Like

I’ll give this (the raycasting) a go, thanks