- Home /
Set default font for Text labels
How can I set default font (I have a .ttf in the Project) for all new Text elements I add to the Hierarchy? I don't want to set the font for each Text I create - this is not good at project start AND it's not good because you just can't change the font project way just like that, you have to find all Text objects in the editor and change them one by one.
(Unity 4.6)
Answer by GrayLightGames · Apr 14, 2020 at 01:27 AM
Even older question now, but I got around this by making prefabs with the default values I want. Then you can just drop them into your scene. This can also end up helping you if you want to change the font for all your Text objects... or realize you need to resize all your 28 size text to 26 or something. You can also unpack the prefab after you deploy the object if you don't want a linkage. Doesn't require any scripting or assets.
A similar using presets (and this goes for basically anything):
$$anonymous$$ake the kind of text you want, click the little sliders icon at the top right of the component, just next to the options, and save the preset somewhere.
Then go into Edit > Project Settings > Preset $$anonymous$$anager, and click add default preset. Select Component, and search/select your text/T$$anonymous$$P component. Finally, assign the preset to it and viola! Everytime you create a new instance of said component it will automatically assign that preset to it
Answer by HarshadK · Dec 12, 2014 at 10:08 AM
I've answered the exact similar question before on UA: Change All (new) UI Text Font?
The answer goes as below with slight modifications:
There is no straight forward way of doing it but you can write a script to do it for you which works as below.
Get all the child game objects of your Canvas game object. If multiple canvases are there then get child game objects of all those canvases.
Then traverse through all the child game objects to check to see if the game object has a Text component attached to it.
If there is a Text component attached you can access the font variable and set its value to the font you want.
You can also write an editor script to perform this task for you or use ExecuteInEditMode as per your convenience.
Answer by Rodiaz89 · Apr 05, 2015 at 04:54 AM
I know it's an old question but if you don't want to go through the hassle of creating a custom script you can get the asset we made that has that functionality and other helpful functions to help you save time.
check it out if you are interested: It's called Gamestrap UI https://www.assetstore.unity3d.com/en/#!/content/28599
Your answer

Follow this Question
Related Questions
GUIStyle and setting font's 2 Answers
Unity and font licensing 0 Answers
Trouble with fonts. 0 Answers
Use Windows Fonts in Game 1 Answer
Font.CacheFontForText is 87.3% in the profiler and causes a HUGE lag spike 1 Answer