Skip to main content

Indie game storeFree gamesFun gamesHorror games
Game developmentAssetsComics
SalesBundles
Jobs
TagsGame Engines

Negative Width on Rect-Transform causes text to Draw

A topic by Noxlof created Oct 27, 2020 Views: 307 Replies: 4
Viewing posts 1 to 2

Just noticed a not-so-weird situation!
I'm animating a rect-box and have a STM component set to fit the box with some padding. As the animation set the box to be smaller than the padding I end up with a negative rect-transform width which causes STM to render the text by default!

i

I could make a script that just forces the rect to not be negative or disable the STM component when the width is smaller than 0, thought I'd just post this in-case there is already a "fix" or similar solution :-)

STM saved our project btw <3 

Developer

Ah right, I should probably make it disable rendering in this situation... I think the reason it does this is because of how STM evaluates text for auto-wrapping. If the width is 0.001, it'll still put one letter on every line, even if it goes out of bounds, to prevent it from looping forever... so when it's negative, I must have set it to just render the whole thing anyway... so I think disabling the renderer when the width is < 0 is a good solution! I'll mess around with this myself soon and see if I can get it working automatically in the actual build.

Super! I think I got it working with the disabled thing! Also, noticed that setting a text enables the renderer even if it's disabled? o.o

Developer

Woah, do you mean... are you disabling the STM component, gameobject, or the mesh renderer itself? If it's the actual mesh renderer, I probably just have some code to make sure it's active, and I hope the other things work correctly... If not, I'll for sure have to give this a peek soon.

(1 edit)

Found why it rendered when disabled, I used Rebuild AFTER I disabled the STM - component... Which I guess updates the mesh renderer?
EDIT: removed Rebuild and did stm.text = "test" which even if the component is disabled renders the text!