Legacy Documentation: Version 4.5.0

Script language:

  • JS
  • C#
  • Boo
Script language

Select your preferred scripting language. All code snippets will be displayed in this language.

Font.RequestCharactersInTexture

RequestCharactersInTexture(characters: string, size: int = 0, style: FontStyle = FontStyle.Normal): void;
void RequestCharactersInTexture(string characters, int size = 0, FontStyle style = FontStyle.Normal);
def RequestCharactersInTexture(characters as string, size as int = 0, style as FontStyle = FontStyle.Normal) as void

Description

Request characters to be added to the font texture (dynamic fonts only).

Note: You should only ever need to use this when you want to implement your own text rendering. Call this function to request Unity to make sure all the characters in the string characters are available in the font's font texture (and it's characterInfo property). This is useful when you want to implement your own code to render dynamic fonts. You can supply a custom font size and style for the characters. If size is zero (the default), it will use the default size for that font.

RequestCharactersInTexture may cause the font texture to be regenerated if it does not have space to add all the requested characters. If the font texture is regenerated it will only contain characters which have been used using Font.RequestCharactersInTexture, or using Unity's text rendering functions during the last frame. So it is advisable to always call RequestCharactersInTexture for any text on the screen you wish to render using custom font rendering functions, even if the characters are currently present in the texture, to make sure they don't get purged during texture rebuild.

See Also: FontTextureRebuildCallback, GetCharacterInfo.