Event.current.mousePosition relative to?

Hi,

I just found a bug in my code that I only noticed when I started creating GUILayouts away from the default 0, 0.

When I:

Debug.Log(Event.current.type + " - " + Event.current.mousePosition);

I get coordinates local to the GUILayout Area which my button is inside.

This is part of a custom button script, so perhaps it has to do with some other methods I am running. However, these come AFTER the debug and without any clicking, just moving my mouse around the screen to see the values:

        Rect rect = GUILayoutUtility.GetLastRect();

        // Get the ID of the new box 
        int id = GUIUtility.GetControlID(0, FocusType.Passive, rect);

        switch (Event.current.GetTypeForControl(id))
            ...

I’m going to switch to Input but I would like to understand what is happening here.

Cheers,

It looks like I needed different mouse positions for different events, I’m just not sure why.

I got it to work by using the Event.current.mousePosition in the EventType.MouseDown, and Input.mousePosition in EventType.repaint.