Author Topic: UIScrollView: Content Origin not working with dynamic scaled panel (Anchors).  (Read 7576 times)

r0bby

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 1
    • View Profile
I have a vertical scroll view which is dynamically scaled based on screen size using the panel's anchors.  The scroll view has its Content Origin set to Top.  Inside this scroll view I have a grid object which is dynamically populated in Start().  The problem is that the inner grid seems to have its position adjusted based on the size of the scroll view before the dynamic scaling.  I have confirmed that the dynamic scaling doesn't even take affect before the first call of Update() by checking the panel's finalClipRegion from inside Update() (size only updates on the second frame).  Attempts to use UIAnchor component on the grid has the same failed affect as relying on the Content Origin.  Attempting to place a UIWidget with anchoring on the grid makes the scroll view not function at all (just jitters on drag).  I have noticed quite a few similar posts about dynamically scaled scroll views.  Has anyone found a solution to this issue or this a deep rooted bug in the current version of NGUI?

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Call NGUITools.ImmediatelyCreateDrawCalls to force it to update first.

stepanchik

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 9
    • View Profile
Hi, I have the same problem with the scroll view and UIGrid.
Actually, I have 2 lists on both sides of the screen. Everyone has only ONE column in it and it is scrolled up and down. (BTW the vertical positioning does not work if I choose VERTICAL in UI grid. It must stay Horizontal with 1 column)
Both of the grids are located in their own CLIPPED panels. Both panels are ANCHORED to their respective side of the screen. The problem is - when I DO NOT MAXIMIZE ON PLAY it works fine, BUT when it is maximized (or when I change resolution in exe-build) the grid is not visible at all or there is only a part of it visible on the panel (depends on the chosen resolution). According to the Unity editor, the X and Y positions of the grids do not change, while the Panel's positions change according to the anchored data.
I also tried UI Anchor, but as it was mentioned here - scrolling stops to work.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Are your anchors set to update OnEnable or OnUpdate? What version of NGUI are you using? Are grids populated at run time? If so, you need to ResetPosition() on the scroll views.

stepanchik

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 9
    • View Profile
I have the latest NGUI version (updated it yesterday hoping to fix the problem, but it did not help).
Grids are populated in the editor (not at run-time).
I used UI anchor for grid. It does not have OnEnable or OnUpdate events. I tried it with Run Only Once flag set (suppose it is equal to OnEnable) and cleared. In the first case, the grid does not appear on the panel (or only part of it is visible) just like in the case, when there is not UI Anchor at all. In the second case, the grid is shown correctly but it cannot be scrolled(just jitters on drag).

stepanchik

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 9
    • View Profile
Some updates. I tried to add Reposition method in Start and in Awake methods. It did not help. But once I added a delay of half second and called the method in the Update function after the half second is over - it worked fine. The question is: Why the Start and Awake methods do not reposition the Grid according to the Scroll view position?
Setting execution order (UIPanel, UIScrollView, UIGrid, MyGridItem) does not help.
And I have another question: Is there any way to receive event OnWindowResize?

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Awake() is called before everything else, and should never be used for interaction with other components. It's basically a constructor.

Start() is fine, but again -- have to be mindful of the execution order. All anchors are updated in Update(), which always happens after Start(). If you want them to execute right away, you'd need to call UpdateAnchors().

Also, be aware that UIAnchor is a legacy script and should not be used.

stepanchik

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 9
    • View Profile
Call to the Reposition function in the Start or in the first call of Update function does not affect items position. The execution order is shown in my previous post: UIPanel, UIScrollView, UIGrid, MyGridItem. So the UIScrollView should be positioned and after that the reposition should work, but it does not...

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
UIPanel should be last, not first. It's the very last thing to execute in NGUI -- execution order of +300. UIScrollView has no explicit execution order, and runs at Default Time. Same with UIGrid. What does your Script Execution Order screen look like?