Author Topic: Shifted click area in resolution ratio different from monitor native ratio  (Read 4367 times)

kanda

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 9
    • View Profile
Hello,

I have a strange problem in my game that use NGUI for all GUI stuffs. Everything is working fine in most case, but i found an issue when playing selecting in unity player a screen resolution with a different ratio than the screen. For example, choosing to play in 1024x768 (4/3 ratio) on a 16/9 screen. What happen is strange : the gui is displayed perfectly, but the colliders are like all shift on horizontal axis. You have to click on left of the icon area. It only happen with the executable. If you choose any screen resolution in the editor it will always works fine of course. But when playing the executable, in the case explained above, it always going wrong.... Of course if you choose any resolution with same native monitor ratio, it works perfectly.

Any idea why it happens ?? At least, is there any way to shift the position of mouse click so i can adjust it according the screen ratio difference from the native one ?

UIRoot has scaling type to  Pixel Perfect,  minimum height 0, max 320. Camera is ortho, viewport rect x0 / y0 / w1 / h1.  UICamera Event Type is set to 3D World. Unity5.

Thanks in advance.

kanda


« Last Edit: July 25, 2015, 04:43:48 PM by kanda »

kanda

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 9
    • View Profile
I have made another test: i have just built an executable version of the Tutorial 4 sample scene in NGUI sdk: the same bug occurs.... When trying to move the slider or hit the "Click Me" button, i have to click out of the button, on their left relative position to hit them, when playing in a screen resolution with a different ration than the monitor's native ratio. Any way to fix that ?

kanda
« Last Edit: July 25, 2015, 04:44:24 PM by kanda »

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
It's some new bug in Unity likely possibly related to the monitor you're using. I am not able to reproduce it on my end with my Asus VG248QE monitors for example, and I tried on both Unity 4 and 5.

kanda

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 9
    • View Profile
It's some new bug in Unity likely possibly related to the monitor you're using. I am not able to reproduce it on my end with my Asus VG248QE monitors for example, and I tried on both Unity 4 and 5.

Well, i could notice the problem on several monitors/computers, not my main one, sadly.
I wrote 3 fixes:
-first solution, i apply a factor on X touch position when creating the raycast to detect colliders in NGUI source. The factor is  monitor native ratio / choosen resolution ratio. It works perfectly. However, i don't like that way so much, so won't use it in the game.

-Second way to fix the problem, at launch, once the user choose a screen resolution, if it's a different one from the native monitor ratio, i select and force another resolution, one with a same ratio as the monitor and with the closer pixels count to the one the user initially requested.

-And at last, i found out that simply doing that : Screen.SetResolution( Screen.Width, Screen.Height); fixes the problem: unity initialize the screen again, but this time with right screen ratio, adding black bands on left and right part of screen if needed. The click problem is then gone. Very strange, but works fine !

I hope it will be usefull if anyone get the problem too.

(note that i am using unity 5.1.0 and NGUI 3.6.6)

regards

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
You should report it as a bug to Unity as it's clearly a recent issue in Unity 5, but thanks for finding the SetResolution work around in the meantime.