Is it possible to change the font size during runtime?

I tried:

aGuiText.font.material.SetFloat("FontSize", 8f)

but that doesn’t work.

I checked if the FontSize property existed using:

aGuiText.font.material.HasProperty("FontSize")

and it returned true which means that the shader has that property.

Since the shader is the one with that property, I figured I could use:

aGuiText.font.material.shader.SetGlobalFloat("FontSize", 8f)

but it wouldn’t let me access the property from an instance. Fair enough. I can just access it statically. But then, I start to ask myself: if I change the global value of the shader, will that affect all the fonts in the project; and, even if it does only affect the current font, since I’ll be changing a static value, does that mean that I have to change it back to its original value if I want to use the same font again but in its original size? Of course, there’s the question of whether this will actually accomplish what I’m trying to do, which is scale the font size during runtime.

(Creating a copy of the font with different sizes is obviously an option, but do you really want the player to download all those assets just so you can cover all the screen resolutions that your game aims to support? =P)

Shader uniform values are generally set by the renderer as part of submitting a batch. So it’s unlikely that this would do what you wanted it to, if only because the TextRenderer itself would almost certainly overwrite the value you provided. For that matter, the shader parameter is not the only variable that needs to be set in order for the font size to change – it’s just the only one you can see from the script.

For that matter, at screen display sizes, you really want to rasterize the font at its desired resolution; dynamic scaling will lead to blurry, uneven strokes and decrease readability.

Font textures are teeny. They can be compressed very well (either losslessly or through DXT), and they have only one channel. I would be surprised if you had enough font sizes to make a dent in your download size.