Tasharen Entertainment Forum

Support => NGUI 3 Support => Topic started by: Rahaio on September 26, 2013, 12:46:37 PM

Title: NGUI 3.0 - UIAnchor Bug?
Post by: Rahaio on September 26, 2013, 12:46:37 PM
Helllo!

First of all I'd like to say that you're doing an awesome job with NGUI and it's great fun working with it!

Today I upgraded to NGUI 3.0 and I think there's a major bug regarding the UIAnchor.

To describe what this is about, here's an example:

Hierarchy of the scene:
UICamera
UIRoot
   spriteTarget
   sprite

"spriteTarget" has a UISprite with the dimensions of 400x400px.
"sprite" has a UISprite with the dimensions of 60x60px and a UIAnchor with the following values:
Container: "spriteTarget"
Side: "Center"

In the older versions of NGUI the behaviour of the anchor worked like this:
When the "spriteTarget" moves, the "sprite" stayed exactly in the middle of the "spriteTarget" no matter what position the "spriteTarget" had.

In NGUI 3.0 it behaves like this:
When the "spriteTarget" moves, the "sprite" will only stay in the middle of the "spriteTarget" in an area which is exactly as large as the dimensions of the "spriteTarget" - in our case 400x400px. If you move the "spriteTarget" further away, in our case lets say to the position X 300 Y 300, the "sprite" will only move half way (to X 250 Y 250).

There are some screenshots in the attachment to make this whole thing a bit more understandable.

With the UIAnchor working like this none of my menus will be aligned correctly.

Could you guys help me with this one?

Thank you in advance!
Title: Re: NGUI 3.0 - UIAnchor Bug?
Post by: ArenMook on September 26, 2013, 02:01:50 PM
If you want it to stay in the middle, just parent it. You have a rather unusual hierarchy to begin with. I'd becurious to know the settings on the UIRoot.
Title: Re: NGUI 3.0 - UIAnchor Bug?
Post by: Rahaio on September 28, 2013, 05:15:25 AM
Okay, I provided a more complex example to show you how I structure my menus with NGUI 2.6. There's a screenshot and a short video in the attachment.

In the last example the UIRoot still had its default settings, this time I only changed the Scaling Style to "PixelPerfect".

In the "Hierarchy.JPG" you can see how my scene is organized.
The gameobject "02_header" has a child called "01_body" which has a UISprite that is scaled to 40% of the screen width by a UIStretch.
The "02_header" also has some children with the suffix "Anchor" where each of them has an UIAnchor that points to the "01_body".
For example the button will always stay on the left side of the header with an offset of 40px no matter the width of the "01_body" (the "03_buttonAnchor" has a UIAnchor that is set to "Right" and points to the the "01_body", the offset is achieved by the gameobject "01_buttonOffset" which simply has an transform X of -40). It's basically the same with the shadow at the left side of the header and the label.

Structuring my menus this way worked pretty well with NGUI 2.6.

I don't know how I could build e.g. this header by only parenting the gameobjects under each other. Furthermore nesting UISprites was not even possible in the versions of NGUI before 3.0.
Title: Re: NGUI 3.0 - UIAnchor Bug?
Post by: Nicki on September 28, 2013, 02:06:05 PM
I've stumbled on some UIAnchor issues as well, actually.

if you use anchor a widget to a sibling widget with the container and move the "source" one so that it's position is not near 0, then the anchored widget spazzes out and moves to different values.

Very specifically, it happens when the source moves >20 px or <-20 px away from 0 in localPosition.y.

I haven't had time to dig into this issue yet, but I will have to since we're using the anchors all over the place.
Title: Re: NGUI 3.0 - UIAnchor Bug?
Post by: Nicki on September 29, 2013, 09:11:56 AM
So, an update in my related issue: it only occurs when you directly anchor a widget to another widget. If you move it in the Y axis, once you go over a certain threshold the anchored widget "lags" after, moving slightly less than the one it's anchored to.

If you move the primary sprite on the negative X axis, the anchored one just stops once you pass a certain threshold (-45 on mine). Might be something with UIWidget.CalculateBounds

Edit: And it breaks in the negative X if it's anchored to the right - and on the positive X if it's anchored on the left. If it's anchored in the center, then it does the same weird lagging behind as on the Y axis - probably the same issue both axes.

Edit2: Yep, CalculateBounds is definitely broken. If I make it always set wc to null, so it uses the container calculations instead of the wc one, it works fine.
Title: Re: NGUI 3.0 - UIAnchor Bug?
Post by: ArenMook on September 29, 2013, 06:15:18 PM
CalculateBounds takes all children into consideration. Do you?
Title: Re: NGUI 3.0 - UIAnchor Bug?
Post by: Nicki on September 29, 2013, 06:23:37 PM
Does it take siblings into consideration?

I have it set up so there's two widgets next to each other in the hierarchy - and nothing else. Will the anchored widget then take itself into account? If so, then I'd say that's pretty broken. :D

(http://i.imgur.com/KASSKkQ.png)
Title: Re: NGUI 3.0 - UIAnchor Bug?
Post by: ArenMook on September 29, 2013, 06:26:31 PM
No, they don't take themselves into account unless you specify a root object as the container.
Title: Re: NGUI 3.0 - UIAnchor Bug?
Post by: Nicki on September 30, 2013, 03:38:25 AM
Well then, as you can see in the screenshot (note the two inspectors), anchoring a sprite to a sprite sibling doesn't get the right values. There's no offset pixel or relative in the anchor, it's anchored to center and the loose sprite is at 0,100,0 and the anchored is at 0,70,0. :)
Title: Re: NGUI 3.0 - UIAnchor Bug?
Post by: ArenMook on September 30, 2013, 11:02:18 AM
Yup, bug -- line 424 of UIWidget reads:
  1. Bounds b = new Bounds(corners[0], Vector3.zero);
...when it should be:
  1. Bounds b = new Bounds(toLocal.MultiplyPoint3x4(corners[0]), Vector3.zero);
Title: another UIAnchor Bug
Post by: Rahaio on October 07, 2013, 10:03:02 AM
The example I've described at the start of this thread works fine now. Thanks for fixing that!

Unfortunately i came across another bug with the UIAnchor. It's not easy to describe this one so I provided a short video which should show you where this bug appears: https://dl.dropboxusercontent.com/u/19383208/UIAnchorBug.mov

Comments regarding the video:
Please take a short look at the way I structured this scene. I’ll click through every gameobject so you can take a look at their settings in the inspector.
The UIAnchor on the background of "Menu2" points on the background inside “Menu1”.
As soon as I move “Menu1”, the background of “Menu2” is no longer aligned correctly. It should stay at the bottom edge of the longer sprite.
If I move the background of “Menu1” itself everything works fine. It also works fine if I move the “UIPanel”.
Unfortunately that’s not what I want to do. The menus I built are way more complex and need to be structured this way, which worked with NGUI 2.6.

I hope you can fix this bug to make the UIAnchors of NGUI 3.0 work in the same way they did with NGUI 2.6!

Thanks in advance!
Title: Re: NGUI 3.0 - UIAnchor Bug?
Post by: ArenMook on October 08, 2013, 02:08:52 AM
As mentioned earlier in this thread, UIAnchor works on siblings -- that is the container must be beside the UIAnchor. Your UIAnchor is referencing an object in a completely different hierarchy. This limitation is lifted in the latest Pro version, but until then -- make it a sibling.
Title: Re: NGUI 3.0 - UIAnchor Bug?
Post by: Rahaio on October 09, 2013, 04:29:41 AM
Alright, thank you for clearing that up for me!