Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

changing resolution makes buttons not work properly

Discussion in 'UGUI & TextMesh Pro' started by dworm, Jul 23, 2015.

  1. dworm

    dworm

    Joined:
    Jun 17, 2015
    Posts:
    74
    the ui is fine in the editor, and i have a canvas scaler set to scale with screen size in my canvas
    but... trying different resolution makes ui elements go in the right place but their "hitbox" not work anymore, its like the hitbox for the button is fixed in the "subscreen", anyway not there the button is actually placed, to click the button i have to click where the button would be in the default resultion

    anyone knows why?
     
  2. NinjaISV

    NinjaISV

    Joined:
    Dec 29, 2014
    Posts:
    124
    I don't know why this happens, but I know how to fix it. You just have to make it windowed first, then change the resolution, like this:
    Code (CSharp):
    1.         Screen.fullScreen = false;
    2.         Screen.SetResolution (1920, 1080, true);
     
  3. Democide

    Democide

    Joined:
    Jan 29, 2013
    Posts:
    315
    The issue for this is, as far as I can tell, if you go full screen and display a resolution with an aspect ratio that's different from your screen's actual native aspect ratio. At least that seems to do it for me.
     
  4. Velo222

    Velo222

    Joined:
    Apr 29, 2012
    Posts:
    1,437
    This has been an annoying "bug" for awhile now. And by bug, I mean just bad programming really. From the googling I've done, it looks like Unity is aware of this issue actually, but it won't be fixed until 5.2 or a dot release thereafter. Which is somewhat surprising considering how major of a bug this is.

    As Martin said, it has to do with going "fullscreen" mode in dx11 on non-native aspect ratios. If you play around a bit, you'll notice that the "hitbox" of the button (as you put it) works if you minimize your game into windowed mode from fullscreen mode .

    Essentially, the button hitbox follows the "windowed mode" setting, but NOT the fullscreen setting. I can actually click on "ghost" buttons in fullscreen mode if I guess where the button would be in windowed mode -- which I've done more than I should. It could actually be a game itself really: Guess where the button hitbox actually is on the screen in Unity.........Simulator 2015 :)
     
    movra and NinjaISV like this.
  5. NinjaISV

    NinjaISV

    Joined:
    Dec 29, 2014
    Posts:
    124
    Lol, how much is it selling for?
    :D
     
  6. Benfont

    Benfont

    Joined:
    Nov 11, 2017
    Posts:
    21
    Hi I seem to be having the same issue using Unity 2019.4.1f1

    When I scale my game to a different resolution, the UI buttons scale accordingly and they are placed properly. However in order to interact with them I have to click far away from the button (their hitbox has been moved).

    It only happens in fullscreen mode, when I make the game windowed then the error goes away

    is this a bug that still has not been solved in Unity?
     
  7. phmello8

    phmello8

    Joined:
    Aug 15, 2018
    Posts:
    1
    Well, I guess not. Working on 2019.4.17f1 and still getting the same issue...
     
  8. valentin56610

    valentin56610

    Joined:
    Jan 22, 2019
    Posts:
    147
    Well well well … Unity 2021.3.3f1 and still having this issue :)
    It was not here before though, 2021.3.2f1 was fine
    But the new version resurrected it

    however this only happens in windowed and not in fullscreen
     
  9. bbsuuo

    bbsuuo

    Joined:
    Jul 21, 2016
    Posts:
    16
    it's bug from ugui
    Since author has not fixed this problem, I offer a solution:

    this issue from class MultipleDisplayUtilities.RelativeMouseAtScaled
    It is a different call in the editor than it is at build run time
    at a particular resolution, the mouse position is incorrectly calculated

    you can annotation defined include code to ensure same editor if you can custom package ugui ()

    Note: i think this code is to fix the issue, but it's make a bigger issue
    https://forum.unity.com/threads/5-3-multi-display-feature-issues.372604/page-4
     
    Last edited: Jul 29, 2022