Search Unity

[SOLVED] RectMask2D and ScrollRect update

Discussion in 'UGUI & TextMesh Pro' started by Dreams, Nov 5, 2015.

  1. Dreams

    Dreams

    Joined:
    Sep 9, 2011
    Posts:
    22
    I have a ScrollRect with a viewport that contains a RectMask2D.
    The content of the ScrollRect has a list of children, expanding beyond the viewport (so they get culled by the RectMask2D).
    I remove the top most child and move to the top of the list.
    I do so by first setting the childs parent to null and then destroying it, then I set the ScrollRect's verticalNormalizedPosition to 1. This works fine.
    But any element (or subelement) not visible, when doing the verticalNormalizedPosition = 1, will not be shown until after manual scrolling happens.

    Am I missing any layout or mask calls to get it to update?
     
  2. Dreams

    Dreams

    Joined:
    Sep 9, 2011
    Posts:
    22
    Should anyone run into the same problem, a call to Canvas.ForceUpdateCanvases () did the trick for me.
     
  3. OpenXcell-Studio

    OpenXcell-Studio

    Joined:
    Nov 19, 2012
    Posts:
    6
    I did same but didn't work for me, Can you have any other suggestion or solution? I am using unity 5.2.2.
     
  4. Dreams

    Dreams

    Joined:
    Sep 9, 2011
    Posts:
    22
    I tried a bunch of things to get it to do what I wanted. I read someone else yesterday suggesting doing a LayoutRebuilder.ForceRebuildLayoutImmediate to force an update that same frame. Maybe that actually works better, instead of having everything update.
    But mine worked... if LayoutRebuilder doesnt work, try waiting a frame or a second and see if it then triggers the update (whether you do a LayoutRebuilder or a Canvas update)
    (I was/am using 5.2.1p3 btw, but probably gonna make the switch to 5.3 now, because of all the ui updates)
     
  5. Yukichu

    Yukichu

    Joined:
    Apr 2, 2013
    Posts:
    420
    You're using a ScrollRect and RectMask2D... successfully I gather. How did you set it up? I posted a separate thread, but no replies. It must work in some fashion.

    I create ScrollRect, remove RectMask and replace it with RectMask2D in same location. Maybe it's the version I'm on? 5.2.2p4.
     
  6. Dreams

    Dreams

    Joined:
    Sep 9, 2011
    Posts:
    22
    Sry for the late response, Yukichu. I had a release and then holidays, so I forgot to check your question.

    I thought I was using RectMask2D, but I am using a RectMask and not the 2D version, as I had problems with getting the 2D version to work correctly as well. I cant remember what the specific problem was, though, I believe it was a culling problem. Using the RectMask I have not noticed anything problematic in my case.

    I just tried to add a RectMask2D in 5.3.1p1 and it "seems" to work fine, but I have not tested it throughout my application, since the RectMask is doing the job just fine atm.
     
  7. RobertoBubaloZutec

    RobertoBubaloZutec

    Joined:
    Aug 20, 2018
    Posts:
    3
    Horothenic likes this.