PointerEnterHandler apparently not firing
Im creating an interactible computer screen with a custom pointer (by moving an ui element and raycasting from its position). I managed to get that working, and i was able to trigger the pointerDownHandler, pointerUpHandler, pointerClickHandler and the all work perfectly, but for some reason the pointerEnterHandler doesnt seem to do anything, i tried using a script from unity's UI documentation to check if the object is currently highlighted and its not, this is the script i copypasted:
//Use the Selectable class as a base class to access the IsHighlighted method
public class Example : Selectable
{
//Use this to check what Events are happening
BaseEventData m_BaseEvent;
void Update()
{
//Check if the GameObject is being highlighted
if (IsHighlighted())
{
//Output that the GameObject was highlighted, or do something else
Debug.Log("Selectable is Highlighted");
}
}
}
and this is the script im using (made following this YT tutorial, although my implementation is based on direct input from the mouse, instead of how he did it taking look direction as input link text)
the input functions at the bottom are called by an input manager script, those work fine as i did get the buttons to click, its just the Highlighting that wont work for some reason
public class ScreenCursor : MonoBehaviour
{
[SerializeField] RectTransform cursor;
[SerializeField] MouseLook mouseLook;
RectTransform canvas;
GraphicRaycaster raycaster;
List<RaycastResult> results;
List<GameObject> targets;
Rect rect;
Vector2 mouseInput;
bool active = false;
bool sendMouseDown = false;
bool sendMouseUp = false;
bool isMouseDown = false;
void Awake()
{
canvas = GetComponent<RectTransform>();
raycaster = GetComponent<GraphicRaycaster>();
rect = canvas.rect;
results = new List<RaycastResult>();
targets = new List<GameObject>();
}
void Update()
{
GetMouseInput();
MoveCursor();
SendInput();
ResetBools();
}
void SendInput()
{
PointerEventData pointerData = new PointerEventData(EventSystem.current);
Vector2 centeredCursorPosition = new Vector2(cursor.anchoredPosition.x + rect.xMax,
cursor.anchoredPosition.y + rect.yMax);
pointerData.position = centeredCursorPosition;
results.Clear();
raycaster.Raycast(pointerData, results);
foreach(RaycastResult result in results)
{
ExecuteEvents.Execute(result.gameObject, pointerData, ExecuteEvents.pointerEnterHandler);
if (sendMouseDown)
{
ExecuteEvents.Execute(result.gameObject, pointerData, ExecuteEvents.pointerDownHandler);
print("down");
}
else if (sendMouseUp)
{
ExecuteEvents.Execute(result.gameObject, pointerData, ExecuteEvents.pointerUpHandler);
ExecuteEvents.Execute(result.gameObject, pointerData, ExecuteEvents.pointerClickHandler);
print("up");
}
}
}
void GetMouseInput()
{
mouseInput = new Vector2(mouseLook.mousex, mouseLook.mousey);
}
void MoveCursor()
{
Vector2 newPosition = cursor.anchoredPosition + mouseInput;
if (newPosition.x < rect.xMin)
{
cursor.anchoredPosition = new Vector2(rect.xMin, cursor.anchoredPosition.y);
}
else if (newPosition.x > rect.xMax)
{
cursor.anchoredPosition = new Vector2(rect.xMax, cursor.anchoredPosition.y);
}
else
{
cursor.anchoredPosition += new Vector2(mouseInput.x, 0);
}
if (newPosition.y < rect.yMin)
{
cursor.anchoredPosition = new Vector2(cursor.anchoredPosition.x, rect.yMin);
}
else if (newPosition.y > rect.yMax)
{
cursor.anchoredPosition = new Vector2(cursor.anchoredPosition.x, rect.yMax);
}
else
{
cursor.anchoredPosition += new Vector2(0, mouseInput.y);
}
}
public void OnMouseLeftPressed()
{
sendMouseDown = true;
isMouseDown = true;
}
public void OnMouseLeftReleased()
{
sendMouseUp = true;
isMouseDown = false;
}
void ResetBools()
{
sendMouseDown = false;
sendMouseUp = false;
}
}
i spent a couple of days researching before writing this, pls show me how dumb i am and didn't notice the obvious mistake