Input.mousePosition buggy in resizable window (windows exe)

So was trying some unity code with mouse input exported as a windows exe with “resizable window” ticked and there is a bug with the coordinates returned after resizing the window (upwards?) sometimes - when you click in the window beyond where the previously-sized window was the coordinates get ‘cropped’ to the old smaller size.

(i.e. Mouse Coordinates sometimes wrongly reported after window re-sized!)

Any known issue here?

It is not easy to replicate consistently but is a pain when it occurs as mouse clicks throughout certain areas of the window start returning the same x or y coordinate cropped to a min value - Windows 7, latest Unity 4.6.1

Probably related issue - Unity Issue Tracker - MousePosition offset after Screen.SetResolution() in OSX standalone widowed mode
Obviously returning correct mouse position is KEY to many desktop apps and looks like there are issues with re-sized windows. If I get time will try and make steps-to-repro project for a bug report

This is a bug in v5 too it seems: Unity Issue Tracker - [Input] When resizing window, Input.mousePosition will be clamped by the original window size

I wrote this code that really fixes this bug. Of course you should temporarily use it until Unity3d-team fix the bug.

When resolution is changed this code calls function SetResolution(). It makes update internal parameter like screen size for Input.mousePosition. Afther that it works perfectly.

You should create an object of ScreenGuard and call Update() every frame (or you can convert this class to Monobehaviour).

using UnityEngine;

/// <summary>
/// Should use temporarily until Unity3d-team fix the bug
/// http://issuetracker.unity3d.com/issues/input-when-resizing-window-input-dot-mouseposition-will-be-clamped-by-the-original-window-size
/// </summary>
class ScreenGuard
{
    private int prevWidth;
    private int prevHeight;

    private bool isInited = false;


    private void Init()
    {
        prevWidth  = Screen.width;
        prevHeight = Screen.height;

        isInited = true;
    }

    private void SetResolution()
    {
        prevWidth  = Screen.width;
        prevHeight = Screen.height;

        Screen.SetResolution(Screen.width, Screen.height, Screen.fullScreen);
    }

    public void Update()
    {
        if (!isInited)
        {
            Init();
        }

        if ((Screen.width != prevWidth) || (Screen.height != prevHeight))
        {
            SetResolution();
        }
    }
}

Thanks, Dm1try.

Finally, it’s been fixed in the current beta.

I’m still having this issue here (5.0.1.f1)
When I build the scene and maximize the window, the UI stop responding.

i have this problem on unity 5.1.2f1 :frowning:

My old repro works fine in 5.1.2f1.