Author Topic: Anchoring Issues  (Read 240 times)

sdclark79

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 3
    • View Profile
Anchoring Issues
« on: August 01, 2017, 03:52:26 PM »
Hello all!

I am having issues understanding Anchoring.  With the examples you have provided it seems to make sense, it seems to make sense, but my practical applications of it are poor at best.

When using anchoring on a Widget, whatever I am trying to anchor (usually a Sprite to UI Root) stretches out of proportion, usually far outside the camera view.  Resizing it only remains until I hit "Play", then is resized to back outside the camera. 

This happens for both Unified and Advanced, and setting the value manually doesn't seem to help, or at least I don't maybe understand the concept fully.  I would imagine -9 from the top and -9 from the bottom of UIRoot would space it 9 units from the top and 9 units from the bottom.

I'm not trying to do anything fancy, just to get menus that will resize based on the resolution.

Any ideas on what I'm doing wrong?  Looked through the forums as well, I'm surprised I couldn't find anyone else having this issue!

Thanks all!

Steve

sdclark79

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 3
    • View Profile
Re: Anchoring Issues
« Reply #1 on: August 01, 2017, 08:41:18 PM »
The attached images show before using the anchor and after.

sdclark79

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 3
    • View Profile
Re: Anchoring Issues
« Reply #2 on: August 02, 2017, 01:15:45 AM »
So far, the solution seems to be working backwards through the elements, anchoring child UI elements to the UI parent before anchoring the UI parent to say, UIRoot.

Is that correct?  Or am I missing the beauty of simplicity?

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 316
  • -Receive: 1149
  • Posts: 22,027
  • Toronto, Canada
    • View Profile
Re: Anchoring Issues
« Reply #3 on: August 03, 2017, 04:01:50 AM »
This is correct. Child should anchor to parent, parent to its parent, etc. It's meant to be hierarchical. Anchoring to siblings and especially children can lead to all kinds of issues -- and anchoring child to root while its parent is also anchored to root can also cause problems.

For "why", consider this use case. 2 widgets:

Root
- A
-- B

Both A and B are anchored to "Root". Since B is a child, it means its position is going to be changed whenever A's position changes. Normally NGUI does anchor updates in order, but in this case "B" may get its Update() call first. NGUI will do its check: is the parent's anchoring updated? In this case it's going to be "Root". It will update "Root", then update "B".

Then Widget A's Update() gets called. it does the same check: is the widget its anchored to updated? Yes, Root was already updated. So it updates "B". But updating B's transform effectively moves A's transform as well. Now "A" looks visibly offset.

See the issue? Setting up anchors in a hierarchical manner avoids this problem.