Author Topic: Unreliable anchoring  (Read 1230 times)


  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 32
    • View Profile
Unreliable anchoring
« on: March 11, 2014, 07:50:40 AM »
Hi all

I'm extremely close to getting my anchoring working correctly, but this one last thing is causing me to lose sleep.

I have a perspective camera, I have an orthographic camera in my menu hierarchy, and I have some GameObjects that are rotating around a (invisible) sphere:

I'm instantiating some UITextures via NGUITools.AddChild(uiRoot, prefab) and using SetAnchor to make them follow my GameObjects.

This is what it should look like:

(Perspective camera, gizmos)

(Both cameras)

However, when I first start my scene I get this (Yellow lines show where the anchor is with respect to the UIRect):

(perspective camera)

(both cameras)

Now, my UITextures are hooked up, via click event, to a mechanism that essentially calls SetAnchor a bunch of times. By clicking all UITextures in turn I can "fix" the anchoring:

Alternatively, moving the GameObjects does not fix the anchoring:

Can anyone offer any suggestions as to how I can fix my anchoring?

From reading the NGUI source, if I was to hazard a guess, I would say the issue would be to do with the way UIRect looks up the camera for each side.


  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Unreliable anchoring
« Reply #1 on: March 11, 2014, 04:31:45 PM »
I am not quite clear on what it is you're actually doing, but NGUI finds the appropriate camera by going through available cameras and checking which camera is drawing the target object's layer. Weird things will happen if you have the target object on the wrong layer, or if more than one camera can see the target object.