[kinda solved] Use TextMesh Pro overflow pages but also fitted scrolling for single pages

Hello, dear helpful people :stuck_out_tongue:
I recently started using TMP. Although it brings a lot of functionality with it, I encountered a “problem”.

What I want:
Text in a message box scrollable and dividable into pages.

What I am trying:
Using a normal scroll view to make the text scrollable, a content size fitter to adjust the scrollable rect to the message length & the TMP pages-overflow to split the text into separate messages using the tag.

Problem:
The content size fitter fits the rect for all pages according to the longest page, instead of only to the text of the current page.

Is there a way to “refresh” the content size fitter? So when I change the page number it’ll automatically try to fit the size of the new content? If that’s not the case, I’d really appreciate suggestions for an alternative solution to this.

(Here’s a short video showing the problem in unity: GoogleDrive)

Thanks!
Dario

I figured out an alternative (temporary) solution to this. Temporary, since I still hope to get the content size fitter “fitting” to the page displayed or for TMP to include this fuctionality on its own someday.

What I did was inserting a new rect as parent to the TMP.go. This rect is what can be scrolled now, then I adjusted the height of this rect to the delta between upper edge of the rect and the y.position of the last character of the page.

(Note: the upper edge of the rect is located at y=0, if I move the text window to another position, I’d need to get the new y-coordinate of it & and subtract it from the position of the character)

//...

public TextMeshProUGUI msg;
//the TMP.go, it still has a content size fitter component attached to it, just so there is no possibility for overhead which could be cut off by the pages-overflow mode.
public RectTransform text_rect;
//the recttransform of the inserted parent

//...

public void AdjustScrollRect()
    {
        msg.ForceMeshUpdate();
        Debug.Log(msg.textInfo.pageInfo[active_page-1].lastCharacterIndex);
        int c = msg.textInfo.pageInfo[active_page-1].lastCharacterIndex;
        Debug.Log(msg.textInfo.characterInfo[c].bottomRight);
        float delta = msg.textInfo.characterInfo[c].bottomRight.y;
        text_rect.SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, Mathf.Clamp(Mathf.Abs(delta), 125, float.PositiveInfinity));
        text_rect.ForceUpdateRectTransforms();
    }

I call this function at start & every time I switch to another page. 125 is the height of the viewport, so I clamped the value. The active-page is what you could type in manually in the edtior - it start with 1, but for the page info it starts with 0, so I had to subtract 1.