Author Topic: Force refresh of child/anchored element dimensions  (Read 4880 times)

Real World

  • Newbie
  • *
  • Thank You
  • -Given: 2
  • -Receive: 0
  • Posts: 15
    • View Profile
Force refresh of child/anchored element dimensions
« on: April 13, 2015, 10:13:31 AM »
I'm creating a dynamic menu where the width and height of some menus are set from code.
I have a structure setup like this:

Sprite A - Height set from code
+ Sprite B anchored to the bottom of the parent sprite
+ GameObject with Grid and Widget components - widget is anchored to the parent sprite on all sides apart from the bottom which is anchored to the top of Sprite B

The grid is populated with a dynamic number of sprites. The height and width of these sprites is calculated so that they all fit in the horizontal grid without exceeding the bounds of the widget on the Grid game object.

I'm facing a problem where after I set the height of Sprite A the height of the grid widget is no longer correct. I need the correct height of this widget to be able to calculate how much space there is for the sprites I'm putting in the grid. Setting the height of Sprite A doesnt seem to update its dependants until the next update.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Force refresh of child/anchored element dimensions
« Reply #1 on: April 16, 2015, 05:15:43 AM »
Yes, that's correct. Anchors are updated once per frame at most, and are never immediate unless you make them by broadcasting UpdateAnchors().

Keep in mind you will get better performance if you turn off per-frame updates by setting the Anchor Update condition to Start or OnEnable.