Hi,
I am working a on a tooltip system and I’d like to know if there is a way to get the mouse position (and ultimately the element at that position) without having triggered a mouse event like move or click.
A particular use case that I’m trying to cover is - having an item disappear after a timeout while hovering it, should hide the tooltip as well.
My plan is to poll the the element under the cursor using schedule.Every, however I can’t find a way to detect the mouse position inside the schedule function. I tried Input.mousePosition but it returns the same position every time.
I could trigger an invalidation event when the item disappears but I don’t want to go that route because it won’t scale well.
What position does it return? I wonder if the scheduler updates at a time before inputs have been processed, or after the current inputs have been flushed. Or can you share your code? Maybe you’re capturing something by reference in the lambda.
Have you tried the new Input System’s method of getting the current pointer position?
Maybe this is something you need to poll from a monobehaviour instead, or potentially use async/awaitables (or maybe UniTask) to continually loop around to the right point in the player loop.
I have not tried the new input as I am not on Unity 6, and I don’t want the extra dependency
If the only way to do it is from a MonoBehavior, so be it, but I’d like someone from the staff to confirm so I can discontinue my search.
Well yes, Input.mousePosition is only intended for runtime use. For editor tools you use Event.current.mousePosition, though the current event isn’t always available and can be null under certain circumstances.
You don’t need to be using Unity 6 to use the new Input system? It’s been around for years and works fine in older versions. Even then it’s not intended to get the cursor position outside of runtime.