Support => NGUI 3 Support => Topic started by: DJVDJV on June 16, 2015, 09:04:24 AM
Title: Ngui Button collider problem
Post by: DJVDJV on June 16, 2015, 09:04:24 AM
Ngui button collider problem.
I have Ngui button (Prefab from tutorial) in Unity 5 project. Buttons collider seems to "move" in different resolutions. Like in fullscreen it is about one button wide too much left.. (So clicks are counted if I click left away from button). What might cause this? Is some reolutions it works fine.
In short: Why resolution affects place of button collider? How to fix it?
Title: Re: Ngui Button collider problem
Post by: DJVDJV on June 16, 2015, 09:50:48 AM
More info: Seems only full screen mode. Low resolution is full screen --> More offset for collider.
640x480 worst offset for collider. 1980x1080 seems to be Ok (No offset)
Title: Re: Ngui Button collider problem
Post by: ArenMook on June 16, 2015, 12:59:57 PM
What are your UIRoot settings? What type of colliders are they, 2D or 3D? NGUI automatically updates widget colliders to match widget dimensions by default, unless you explicitly disabled that option. Look for the "Collider" option on your widgets.
Title: Re: Ngui Button collider problem
Post by: DJVDJV on June 16, 2015, 02:06:11 PM
Hello,
Colliders = "Box collider"
Root setings:
Scaling style = Flexible; min height = 320 max height = 1536 shrink portrait ui = Unchecked Adjust by DPI = Unchecked
Autoadjust on collider = Checked
Title: Re: Ngui Button collider problem
Post by: ArenMook on June 18, 2015, 07:44:47 AM
I just tried this in Unity 5 with the latest version of NGUI:
1. New scene. 2. ALT+SHIFT+S, ALT+SHIFT+C, positioned the sprite in the top left corner of the screen and anchored it to top-left. 3. Placed a UIButton on it so I can see its color change. 4. Build & run, choose 640x480, hover over the sprite -- works as expected.
What are you doing differently?
Title: Re: Ngui Button collider problem
Post by: DJVDJV on June 22, 2015, 12:44:56 AM
Hello,
I started new project and did this simple example:
""1. New scene. 2. ALT+SHIFT+S, ALT+SHIFT+C, positioned the sprite in the top left corner of the screen and anchored it to top-left. 3. Placed a UIButton on it so I can see its color change. 4. Build & run, choose 640x480, hover over the sprite -- works as expected.""
Run project in 640x480 fullscreen... and colliders are broken: * about half of button size offset to left in 640 x 480 * went better in bigger resolutions * in windowed mode all OK on every resolutios (Just same as in my game project)
Got: Unity 5.0.2 Ngui: Fresh from assetstore, Version: 3.9.0b (Jun 11, 2015) Windows 8.1 64bit CPU i5-4670k Not touchscreen NVIDIA GeForce GTX 760
Title: Re: Ngui Button collider problem
Post by: DJVDJV on June 22, 2015, 01:41:22 AM
Just upgraded Unity to 5.1.1 and same problem occurs.
Title: Re: Ngui Button collider problem
Post by: Matthew on June 22, 2015, 03:48:26 PM
I'm experiencing the same issue. Though I can only reproduce in the standalone game (not in editor), by switching to a nonstandard resultion, windowedmode, then back to fullscreen.
When returning to fullscreen all of the colliders will be offset.
I was looking through the code and forums, and thought that maybe UIWidget.ResizeCollider() wasn't being called. But it turns out UIButtons are not uiwidgets.
Anything else to try?
Title: Re: Ngui Button collider problem
Post by: ArenMook on June 25, 2015, 07:50:35 PM
The buttons are widgets if you make them as such. ALT+SHIFT+W adds a widget -- put a UIButton script on it instead of an empty game object.
I am not able to reproduce any issues on my end. @DJDJV: I am not sure what "half the buttons" you are talking about -- the example I posted only had 1. Please provide clear instructions on how to reproduce the issue or I won't be able to do anything.
Title: Re: Ngui Button collider problem
Post by: DJVDJV on June 26, 2015, 01:09:51 AM
Hello, I make it as simple as possible now:
Here step by step:
1) Create new Project (2D) (v.5.1.1f1) 2) Imported NGUI v 3.9.0b to project 3) Added new button (Colored button) from "Prefab Toolbar" 4) Build project
5) Run it on 640x480 FULLSCREEN 6) Mouse over button 7) Problem.png It is now mouse over! (I draw place of collider as red)
Continue testing: 8) Run it on 640x480 WINDOWED 9) Mouse over button works OK. Collider in right place
Title: Re: Ngui Button collider problem
Post by: ArenMook on June 29, 2015, 06:52:29 AM
Ok the problem is the 2D part I'm guessing. Can you try it with a 3D project? Keep in mind that NGUI uses 3D colliders by default -- this includes the collider on the prefab button you used.
Title: Re: Ngui Button collider problem
Post by: DJVDJV on June 29, 2015, 05:55:55 PM
Now it is strange.
I did:
1) Create new Project (3D) (v.5.1.1f1) 2) Imported NGUI v 3.9.0b to project 3) Added new button (Colored button) from "Prefab Toolbar" 4) Build project
Still problem here with Full screen (640x480).
I changed NGUI-> Extras -> "Switch to 2D colliders" and still NO luck.
Title: Re: Ngui Button collider problem
Post by: DJVDJV on June 29, 2015, 05:59:34 PM
Additional info (if needed)
My screen resolution is 2560x1440
Title: Re: Ngui Button collider problem
Post by: ArenMook on July 03, 2015, 11:31:15 AM
I followed your steps... everything worked as expected but I am in Unity 5.0.2, which is the only difference I can think of. I created a project with NGUI in it, added the button at -150, 100, built, went 640x480 full screen, button works fine. ALT+Enter to go windowed, works fine. ALT+Enter to go full screen, works fine. You said you used 5.0.2 earlier as well, so I am not sure what else you could be doing differently...
Title: Re: Ngui Button collider problem
Post by: Matthew on July 13, 2015, 01:41:47 PM
Hey ArenMook,
I've been able to reproduce the bug using the free version of NGUI. I've attached a project that modifies your button example scene. I've tried to attach a project that modifies your button example scene, but the rar file is too large. Instead I've attached a script that will rotate through resolutions when the spacebar is pressed. Put this script on the root node of Tutorial 6. (I can email you the project if you provide an email)
By pressing the space bar, the app will cycle through resolutions. When the aspect ratio of the resolution doesn't math my monitor, I experience the bug.
(Only reproducible in standalone)
Title: Re: Ngui Button collider problem
Post by: ArenMook on July 14, 2015, 11:59:13 PM
Free version of NGUI hasn't been supported in a long time, there's not much I can do with it.
Title: Re: Ngui Button collider problem
Post by: DJVDJV on July 16, 2015, 01:05:20 PM
I think it is not because of free version. I have most recent NGUI and most recent Unity.
Title: Re: Ngui Button collider problem
Post by: SoullessDreamer on August 29, 2015, 04:59:09 AM
I have had the same issue as well. However I have figured out why this is happening. When you lower the resolution on the standalone of the game. Lower than the resolution your PC is set at, the colliders of the buttons are thrown off. More so on the buttons set on the right side of the screen than the left.
To fix this: If you set your monitor resolution to the resolution you are going to test the standalone game on before you start the game. Everything will work as intended. So, if your user needs to set their resolution on the standalone to a lower one than their native resolution. Then they will need to change their PC resolution through windows before launching the game.
This seems to have fixed the issue across multiple alpha testers we have testing our game. I am working on a 'work around' that doesn't involve the user changing the PC's resolution before going into game. If I achieve this I will post here with how I was able to fix it.
I hope this temporary fix helps others.
Title: Re: Ngui Button collider problem
Post by: computernerd92708 on September 03, 2015, 05:03:37 AM
This is the same issue I am having. I posted a video of it on Youtube (in the thread I created). Reproduced it in the simplest way possible.
I did what was suggested here (switch to highest possible resolution), and that fixed the colliders. But... there is no way my Surface 3 can support my game at 1920x1280 :(
I cannot even test my game...
And there is no way I am going to require every player to use only the highest resolution possible on their machine.
Title: Re: Ngui Button collider problem
Post by: ArenMook on September 06, 2015, 05:07:25 PM
Have you tried simply forcing Unity to assume a specific resolution on startup?
Screen.SetResolution(width, height, fullScreen);
I force Windward to run at 720p on mobile devices this way and I've never experienced any issues, but then again I am still using Unity 4.6.7 for it.
Title: Re: Ngui Button collider problem
Post by: Matthew on September 16, 2015, 06:45:16 PM
Forcing users to a specific resolution is not a viable option for a commercial product. The free version was used to demonstrate the bug. But the bug occurs in the non-free version.
Is this a bug that you are not interested in fixing?
Title: Re: Ngui Button collider problem
Post by: ArenMook on September 20, 2015, 02:08:42 AM
Are you saying Windward is not a commercial product?
Mobile devices often have insane resolutions with very low power GPUs on tiny screens. Whether the game runs at 4k or 720p on a 5 inch screen is not something you can determine without a magnifying glass, and the 720p offers far better performance.
Anyway, all that aside, I was suggesting forcing the Screen.SetResolution to the desired resolution. Ie: if your game should be 1920x1080, set it to exactly that. Basically force Unity to use the resolution it should already be using. That's what I suggested.
As for "fixing" it, the issue is in Unity, not in NGUI -- as evidenced by the fact that it used to work fine in previous versions of Unity. I can only suggest work-arounds for it.
P.S. It's a known Unity issue that also affects Unity's built-in UI exactly the same way: http://issuetracker.unity3d.com/issues/button-position-is-wrong-on-fullscreen-player-which-aspect-ratio-is-different-then-monitors