Author Topic: Updating anchors on Late Update instead  (Read 4891 times)

Prodigga

  • Newbie
  • *
  • Thank You
  • -Given: 1
  • -Receive: 2
  • Posts: 17
    • View Profile
Updating anchors on Late Update instead
« on: February 03, 2015, 10:33:05 PM »
Hey guys

Sometimes, some of my widgets' anchors seem to late begin a single frame. This happens a lot when I have widgets/panels anchored to a widget/panel inside of a scroll view that is moving. When the user drags the scroll view, the objects in the scroll view update and move correctly, but anything outside of the scroll view anchored to those objects lag behind.

I was able to fix this issue by editing UIRect and UIWidget and replacing all the Update calls with LateUpdate. Everything was anchored correctly after that. However, it seems to have brought rise to some culling issues. Sometimes, newly instantiated objects inside of scrolls views won't render correctly (invisible) until I move the scroll view a little.

I don't know what other implications my change would have, so thats why I thought I'd come here first and ask about it. What would I potentially be breaking with this change?

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Updating anchors on Late Update instead
« Reply #1 on: February 05, 2015, 09:06:06 AM »
Anchored things inside a scroll view that's moving? That seems very wrong to me. Most anchors should be set to execute on Start() -- meaning only once. Why anchor something that can move? I don't recommend altering the Update() to LateUpdate(). LateUpdate() is used by the UIPanel to create actual draw calls. Update() is used by the UICamera to send out events. Although going by the script execution order, UICamera will execute before all other scripts, while UIPanel will execute after all other scripts.

Prodigga

  • Newbie
  • *
  • Thank You
  • -Given: 1
  • -Receive: 2
  • Posts: 17
    • View Profile
Re: Updating anchors on Late Update instead
« Reply #2 on: February 05, 2015, 06:36:29 PM »
Basically I have a scroll view full of widgets w/ transparent backgrounds. Then, outside of the scroll view, I have a UIWidget that has its top anchor anchored to the top of the scroll view and bottom anchor anchored to the bottom of the last element in the scroll view. This makes it stretch from the top of the list to the bottom element of that list, and it updates correctly when the user drags the scroll view up and down. It is easier to just show you:


Anyway, it all works fine, except for the update issue I mentioned above. After testing, the strange culling issues I mentioned before seem to be unrelated (I reverted my LateUpdate modification and still had issues with a vanilla UIRect class, so I've posted here.

I've modified UIRect and given it a LateUpdate as well as an Update function. I've added a public bool to UIRect (UseLateUpdate) and if it is checked, the UIRect will run on late update (otherwise the LateUpdate just returns immediately. This way, I don't modify the way NGUI works too drastically - only some of my anchors are updating on LateUpdate and those anchors generally belong to widgets that sit at the bottom of the hierarchy tree and don't have any other objects anchored to them. Havn't had any issues with it so far, its working well!

Prodigga

  • Newbie
  • *
  • Thank You
  • -Given: 1
  • -Receive: 2
  • Posts: 17
    • View Profile
Re: Updating anchors on Late Update instead
« Reply #3 on: February 05, 2015, 07:49:40 PM »