Hi there,
Can somebody help me with this issue. I’m trying to follow a tutorial on creating a basic inventory system, and I’m getting bogged down in one of the early prototyping steps. The particular step involves creating a basic canvas with item slots made from Raw Image UI objects. And then testing whether, or not, the mouse cursor is hovering over said Inventory UI slots.
Utilizing this set up, I’m not getting any recognition that the cursor is hovering over the slot. The code is attached to the slots themselves. so each slot has this code. It all seems super simple, so I was surprised when it didnt work. I’m using Unity 2021.3. The tutorial is using unity 2019, or maybe 2018. Is this method outdated? I did find another tutorial using Unity 2020.xx and the same method.
The slot Raw Images on the canvas are just “as is” I didnt add any components, other than this code, to them. As I didnt see any being added in the tutorial.
Let me know if anyone wants me to follow up with any screen shots. Any help here is super appreciated! hope everyone is having a fantastic week! and Happy 2023!
using UnityEngine;
using UnityEngine.EventSystems;
public class Slot : MonoBehaviour, IPointerEnterHandler, IPointerExitHandler
{
public bool hovered;
void Start()
{
hovered = false;
}
public void OnPointerEnter(PointerEventData eventData)
{
hovered = true;
Debug.Log(“Hovering”);
}
Further Info:
I tried doing the same code in a brand new project… and of course it worked. I also tried redoing it from scratch in my main project but that didnt help.
So this failure to work I think may be driven by some setting in the original project. Any Ideas would be super appreciated! I looked at the package list installed in both projects. They have the same UI package installed, and both same version.
The project that I’m trying to do this in, was originally created as a Unity 2020.xx project and has been updated to Unity 2021.3 (current LTS).
@chemicalcrux I got very excited for a minute. But no avail. Really appreciated the suggestion.
They were both set to “Input Manager (Old)”… tried changing the offending project to “Both”, and “New” … just in case sourcery lol. But I’m no Harry Potter.
Please let me know if you have any other suggestions! Can at least cross this off the list. Thank you again for taking the time to respond.
Do any UI interactions work? If they’re all broken, you probably deleted the EventSystem object that gets generated in the scene when you create a UI element:
If you’re instantiating a bunch of prefabs, and never actually manually created a button/etc. in the scene, then it might never have been created in the first place.
If so, try creating the event system object. It’s under GameObject > UI > EventSystem
This was the issue. I inadvertently deleted the UI Eventsystem Object. Thanks so much for taking the time to follow up @chemicalcrux . I REALLY appreciate it! :):)
Interestingly, for anyone else also having this problem… after fixing it per @chemicalcrux 's suggestions. It would not work with “New Inputs” but the method does work with “Both” I think I’ll leave the project on both, instead of just reverting to “Old”… Was meaning to play around with the new inputs at some point anyway. Might as well update the 1st person controls I made.
Awesome! yeah i’ll have to try playing with the new one. Always forward as it were! This is definitely my first attempt at trying to gain a better, more useful understanding of creating / applying my own UI. So far most of my focus has been on game mechanics and level design. But got to get on that UI train. It’s a super important component for the kinds of games that I’d like to work my way up to creating.