Author Topic: How to update anchors properly?  (Read 4164 times)

Anubis

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 4
    • View Profile
How to update anchors properly?
« on: September 17, 2015, 04:05:45 AM »
Trying to manually update anchors for widgets. In some cases they ignoring command <UpdateAnchors>. If I just use «Execute <OnUpdate>» policy on them, they updating in second frame, which causing some ugly looking lag.

Repositioning works only if child labels set to OnEnable and parent container set to OnUpdate. I'd like to update them all manually only when updating labels content.

Maybe I'm blind, but can't see any anchor tutorials. Please help and tell me how to order widgets update their anchors. Thanks.
« Last Edit: September 17, 2015, 04:49:59 AM by Anubis »

Anubis

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 4
    • View Profile
Re: How to update anchors properly?
« Reply #1 on: September 17, 2015, 05:03:28 AM »
The only way I've made it work correctly at this moment is by using coroutine to wait a frame and then update container's anchors:

moneyLabel.UpdateAnchors();
yield return new WaitForEndOfFrame();
moneyBlock.UpdateAnchors();

Is there any better solution?

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: How to update anchors properly?
« Reply #2 on: September 20, 2015, 02:32:01 AM »
Use ResetAndUpdateAnchors(), not UpdateAnchors().

Anubis

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 4
    • View Profile
Re: How to update anchors properly?
« Reply #3 on: September 22, 2015, 11:09:52 PM »
I see no difference. And in some situations even waiting for next frame before updating container's anchors gives no effect.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: How to update anchors properly?
« Reply #4 on: September 26, 2015, 04:24:21 PM »
I've made some minor changes related to anchoring in the current Pro version, so please see if it works properly after the update, and if not -- please submit a simple repro case for me to look at.

In general, simply broadcasting UpdateAnchors() after changing something is more than enough for everything to update properly.
  1. rootWidget.BroadcastMessage("UpdateAnchors");