Indie game storeFree gamesFun gamesHorror games
Game developmentAssetsComics

[solved] Allow bounding box to exceed RectTransform's size?

A topic by Scarlet String Studios created May 05, 2018 Views: 347 Replies: 8
Viewing posts 1 to 9
(1 edit)

I just updated to STM 1.7.1 and Unity 2018, and I'm running into an issue with bounding box sizes. It might have something to do with the new VerticalLimitMode.

I have a text mesh that's used as the Content for a ScrollRect. I want the mesh to grow as more text is added to it, until it's eventually cropped off by a Mask component in the parent ScrollRect. Then, the player can scroll through the oversized text via the ScrollRect. Because of the ScrollRect, I can't attach a ContentSizeFitter to the text mesh — I think they conflict somehow, because Unity throws a warning and the scroll no longer works.

In the past, I think the STM bounding box automatically grew as text was appended, so all I had to do was manually resize the RectTransform to match it (via rawTopLeftBounds and rawBottomRightBounds). But no matter which VerticalLimitMode option I choose, the bounding box doesn't exceed the RectTransform's size — which means its rect can't become bigger than its parent's rect, and so it can't be scrolled through.



In 1.7 I started making it so STM will act more naturally like Unity's Text component, but I'm starting to regret doing this... it's supposed to use the Content Size Fitter or other layout elements to determine the size, so I'm not too sure what to do here? I could try adding back the old methods in the next update under a bool maybe? Right now it works like... Unity UI text always assumes autoWrap is set to the rectTransform's width, and verticalLimit is set to the rectTransform's height, so those properties are always on and the content size fitter just expands the rect to fit all potential text.

Sorry for the mess this has caused, I won't be able to fix this for about 2 weeks or so, but I really would like to solve this issue of how STM should behave with Unity UI once and for all.

Okay, good to know how this is supposed to work at any rate. I can try to find a solution with ContentSizeFitter.

Can you double check that the UIMasked shader is still working in this update? I created a new game object in my canvas, gave it a Mask component, then created a child and gave it a SuperTextMesh with the UIMasked material. The text doesn't appear at all, whether it's inside or outside the mask. I can only see it if I change the material to Default or UIDefault.


The UIMasked shader is a bit... strange. A friend of mine figured out you can use stencil masks to work with unity UI masks, so it uses that to work, not the intended "MaskableGraphic" method most UI elements use. Either way, I don't think it should have changed in this update, even with the shader cleanup? Another user on twitter was using the UIMasked shader not too long ago, so I'm trying to figure out what could be causing different behaviour this time around?

Interesting. I've read a bit about the stencil buffer but I never fully understood it. What's the correct setup for UIMasked exactly? How should the parent be set, how should the child be set? Maybe some setting is off.


I don't actually use Unity UI myself, but I could swear it was just... if the child has the mask shader, it'll clip to be within the parent?

(1 edit)

Ok so we can put Unity's Mask component aside for now. Just looking at UIMasked, the Stencil section says...

Ref 0 (the value to look for in the stencil buffer)

Comp Less (if the stencil buffer's value is less than 0, then draw this pixel)

Is my understanding correct? So... does this mean the parent has to write -1 to the stencil buffer for any pixels to be drawn? Sorry if this is basic stuff; just trying to understand what's happening here so I can troubleshoot.

EDIT: I kinda got this working? I just copied the stencil segment from a sprite mask shader that I was using elsewhere. Right now it's:

- Ref 1

- Comp equal

- Pass keep

And this appears to work with Unity's UI Mask component. I think the Mask writes 1s across the whole rect, and this shader keeps whatever pixels were written as 1 (anything within the parent rect). Dunno if this is how it's supposed to work, but at a glance it's working!

Update on this: the Mask is working, and I set up the ScrollRect as per this thread, after some confusion. It's working with the Unity Text component but not with STM. The sizeDelta.y of both the Content wrapper object and its Text child remain at 0, even as the STM bounding box grows bigger. I can work around this by manually setting the Content's sizeDelta to match the bounding box, but I'm guessing this isn't expected behavior.


Sorry for the late reply, but yeah yikes, I'll see what I can do to add back the old behaviour for edge cases such as this. I think adding back the booleans for text wrap during UI mode should do it.