Author Topic: UIAnchor z-pos constantly decreasing  (Read 3588 times)

Rednaxela

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 11
    • View Profile
UIAnchor z-pos constantly decreasing
« on: July 01, 2013, 07:48:07 AM »
I have couple of UISprites with attached UIAnchor scripts on them (excluding first one, called Background), some kind of hierarchy (Icon -> LBackground -> Background). Each of them has a WidgetContainer object (Icon has LBackground , LBackground  has Background). Icon's and LBackground's z-position constantly decreasing if UIAnchor script is active, if i disable it - decreasing stops.

Nicki

  • Global Moderator
  • Hero Member
  • *****
  • Thank You
  • -Given: 33
  • -Receive: 141
  • Posts: 1,768
    • View Profile
Re: UIAnchor z-pos constantly decreasing
« Reply #1 on: July 01, 2013, 07:03:15 PM »
Sounds like floating point inaccuracy. Layering UIAnchors in that manner can get a little dodgy.

I recommend you use the fancy new "Run Only Once" if you can, so it doesn't run away like that.

Alternatively, you should change the UIAnchor to not change if the values are less than 1.0f.

dlewis

  • Guest
Re: UIAnchor z-pos constantly decreasing
« Reply #2 on: July 01, 2013, 08:09:07 PM »
We had the same problem and I was never able to figure it out before I moved off the project. I think it was causing significant performance problems for us.

Nicki

  • Global Moderator
  • Hero Member
  • *****
  • Thank You
  • -Given: 33
  • -Receive: 141
  • Posts: 1,768
    • View Profile
Re: UIAnchor z-pos constantly decreasing
« Reply #3 on: July 02, 2013, 05:50:25 AM »
Yeah, if it is a complex panel, then constantly shifting the position causes the UIPanel to UpdateGeometry every update which is a costly affair. The RunOnlyOnce is a great thing to use in that case.

Rednaxela

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 11
    • View Profile
Re: UIAnchor z-pos constantly decreasing
« Reply #4 on: July 02, 2013, 07:31:47 AM »
Nicki, I can't use that option. But I have found similar solution - after re-positioning and re-sizing of all needed elements of GUI, I simply destroy all UIAnchor scripts from transform:

UIAnchor[] uiAnchors = transform.GetComponentsInChildren<UIAnchor>();
        foreach (UIAnchor uiAnchor in uiAnchors)
            Destroy(uiAnchor);

Thanks all for replies.