Author Topic: ResetPosition on UIScrollView not working before anchors have equalized  (Read 6074 times)

Wisteso

  • Full Member
  • ***
  • Thank You
  • -Given: 21
  • -Receive: 3
  • Posts: 103
    • View Profile
This is a (very delayed) followup from http://www.tasharen.com/forum/index.php?topic=9751 but since that topic kind of went on a different tangent, I'm creating a separate post.

TL;DR is...

  • Game loads up with this GUI area preemptively disabled
  • GUI area is enabled for first time, nested UIScrollView.ResetPosition() runs in the same frame with no effect
  • (Im guessing) Immediately afterward, in LateUpdate()? maybe, UIPanel anchors realign themselves (based on UIRoot size)
  • GUI area is disabled and enabled again, ResetPosition() runs in same frame and works this time (and every additional time afterward)

I've tried running UpdateAnchors, Refresh, and a few other things immediately before calling ResetPosition but no luck. I was nesting some anchors, but now have most anchors working off of UIRoot (when possible) rather than having a small anchor decency chain.

If I run ResetPosition() after 0.25 seconds instead of immediately after enabling the GUI area, it also works but looks hacky. Pretty sure the issue is that the anchors need to be refreshed before calling ResetPosition but I want to leave these areas disabled when not being used, for performance reasons.
« Last Edit: May 12, 2015, 12:48:42 PM by Wisteso »

Wisteso

  • Full Member
  • ***
  • Thank You
  • -Given: 21
  • -Receive: 3
  • Posts: 103
    • View Profile
Did some debugging / experimenting with the UIPanel and found out that indeed, the issue was due to OnAnchor being executed (for the first time) after ResetPosition was called (for the first time). OnAnchor is run as part of Update() on the UIPanel, so I just replaced the call to UIPanel.Refresh() with a call to UIPanel.Update() instead and viola. Issue solved.

obj.GetComponent<UIPanel>().Update();
obj.GetComponent<UIScrollView>().ResetPosition();