Search Unity

Question Can't scroll to bottom of ScrollView

Discussion in 'UGUI & TextMesh Pro' started by Corva-Nocta, Nov 20, 2022.

  1. Corva-Nocta

    Corva-Nocta

    Joined:
    Feb 7, 2013
    Posts:
    801
    Hey all,
    Asked a while back to get some help and tried a few things and none of them are working. I honestly can't believe something so simple is so complicated. All I am trying to do is scroll to the bottom of a ScrollView UI window after I add a new message, essentially just created the exact same look as any chat app or teting app. I've been banging my head against a wall for days and searching everywhere online, it simply refuses to scroll no matter what I try. So I am hoping someone knows how to make this happen!

    I've got a ScrollView UI object, the Content child object has a Vertical Layout Group so everything gets stacked up properly. This part works fine, when I add a new message it shows up and appears under the previous message. The problem is when the stack of messages hits the bottom of the ScrollView. When I add more messages they just flow down, but the ScrollView will never scroll down to see them.

    I've found a few pieces of code, but they do literally nothing and I don't know what is wrong. I have tried this:

    Code (csharp):
    1. scrollRect.verticalNormalizedPosition = 0;
    and it does nothing.

    I tried:

    Code (csharp):
    1.  
    2. Canvas.ForceUpdateCanvases();
    3. scrollRect.content.GetComponent<VerticalLayoutGroup>().CalculateLayoutInputVertical() ;
    4. scrollRect.content.GetComponent<ContentSizeFitter>().SetLayoutVertical() ;
    5. scrollRect.verticalNormalizedPosition = 0
    again, literally nothing.

    I even tried putting these codes into the Update function just to make sure it wasn't a problem with the timing. Still no movement of any kind.

    I am really at a loss here and just pulling my hair out. Does anyone know anything about how to scroll to the bottom of a ScrollView? Or any good info for how to copy the type of messaging as in a chat app or texting app?
     
  2. Mconkla

    Mconkla

    Joined:
    Nov 23, 2019
    Posts:
    1
    Code (CSharp):
    1.   public static void RecalculateVerticalLayoutGroup(VerticalLayoutGroup verticalLayoutGroup)
    2.    {
    3.       verticalLayoutGroup.CalculateLayoutInputHorizontal();
    4.       verticalLayoutGroup.CalculateLayoutInputVertical();
    5.       verticalLayoutGroup.SetLayoutHorizontal();
    6.       verticalLayoutGroup.SetLayoutVertical();
    7.    }