Author Topic: UIWrapContent Reposition Issues  (Read 3764 times)

pmaconi

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 6
    • View Profile
UIWrapContent Reposition Issues
« on: August 04, 2014, 12:14:29 PM »
Hello -

I'm currently using UIWrapContent to display a variable sized list of items (so not unlimited). When I populate the items, I want to reset the scroll view so the list starts at the beginning. However, there seems to be a time delay before that is possible using mScroll.ResetPosition(). If I wait a few frames, it works as expected. But I don't seem to be able to populate the items and then reset the scroll view in the same frame. Is there something else I should be doing?

Thanks.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: UIWrapContent Reposition Issues
« Reply #1 on: August 05, 2014, 12:09:42 PM »
Newly created widgets are not added immediately on Awake()/OnEnable(). There is some delay, and it eventually happens in Update(). You can force it to be earlier by using NGUITools.ImmediatelyCreateDrawCalls. So create your items, call that function, then reset the scroll view.

pmaconi

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 6
    • View Profile
Re: UIWrapContent Reposition Issues
« Reply #2 on: August 05, 2014, 01:52:09 PM »
Is there a way to achieve my desired result without the massive hitch from calling NGUITools.ImmediatelyCreateDrawCalls(_uiWrapContent.gameObject)? I'm seeing 500kb of GC alloc and 250+ ms while in deep profile in the editor (with OnValidate commented out). I'm just looking to make the list start at the beginning immediately after opening the dialog. Being able to focus on a specific item would also be really useful, but isn't quite critical yet.

My hierarchy looks like this, in case it's relevant:
Scroll View/Panel
- UIWrapContent
--UIWidget (x8)
---UIWidget (sprite, label, etc) x16

As a separate issue, UIWrapContent seems to have problems when dealing with an inaccurate number of children and a restricted range (either too few children or too many). I fixed these problems locally, but figured it would be useful to bring to your attention. I was seeing some items not being initialized when mFirstTime is set and others remaining visible even if their realIndex is out of range of minIndex and maxIndex. Also, the following assignment is only happening in either vertical or horizontal mode (I forget which). Is that intended?

mScroll.restrictWithinPanel = !allWithinRange;

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: UIWrapContent Reposition Issues
« Reply #3 on: August 05, 2014, 02:01:31 PM »
Deep Profile should never be relied upon for anything. I wrote about this many, many times now, and Unity themselves warn about the same thing.

No, the mScroll line should be there for both. I'll fix that, thanks.

pmaconi

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 6
    • View Profile
Re: UIWrapContent Reposition Issues
« Reply #4 on: August 05, 2014, 02:58:48 PM »
Sure, I know. But the hitch is bad and extremely noticeable even with deep profiling off.

pmaconi

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 6
    • View Profile
Re: UIWrapContent Reposition Issues
« Reply #5 on: August 07, 2014, 02:33:59 PM »
Apologies for the bump in case you were planning to come back to this thread. Is there any way other than NGUITools.ImmediatelyCreateDrawCalls to force the scroll view to the beginning of the UIWrapContent list?

ImmediatelyCreateDrawCalls has way too high of an overhead for me to use it in this instance. I'm seeing delays of up to a second when attempting to use it repeatedly (without profiling). For more context, I have a UIWrapContent that I'm repopulating when the user clicks on a different category tab.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: UIWrapContent Reposition Issues
« Reply #6 on: August 08, 2014, 08:26:27 AM »
You can try just doing a broadcast of "CreatePanel" instead. Doing that registers widgets with the panel, and should technically achieve the same effect for less cost.

pmaconi

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 6
    • View Profile
Re: UIWrapContent Reposition Issues
« Reply #7 on: August 08, 2014, 04:17:59 PM »
Thanks, I'll give that a try.