- Home /
Change All (new) UI Text Font?
Hello, I'm using the new UI in unity 4.6 and I made a bunch of elements (menus, options screens, etc) which involves a lot of UI text in the buttons and titles, and the thing is that I would like to change all the fonts to a specific one, is there a way to make it in one action or do I simple have to do it one by one?
Answer by HarshadK · Sep 12, 2014 at 01:24 PM
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.
Make sure you set this script to ExecuteInEditMode.
I would prefer a "non-scripted way", but I guess I have no other choice.
Anyway, impressive detailed and quick reply! Thank you a lot.
I made an asset that has this functionality plus other features, it's called Gamestrap UI and you can just select the components you want to change it's font and it will go through every child recursively and set the font if it has a text component. https://www.assetstore.unity3d.com/#!/content/28599
Is this a 'expensive' of doing it? I'm trying to find a better way...
Answer by rakkarage · Sep 15, 2014 at 02:08 AM
search for UnityEngine.UI.Text select them all then change and they all change
Answer by Azzerhoden · Apr 13, 2015 at 01:06 PM
I just opened a scene, searched in the Hierarchy window for Text, selected them all, and changed them. This will only work if you hadn't changed the name of the text object.
As a matter of habit all of my Text components are within a panel or other object, so I never change the name.
In the Hierarchy window, if you click on the magnifying glass/dropdown, you can change it to search by Type, and then you can put in Text, it'll find all text objects regardless of the name you give it.
Answer by GrantTheAnt · Mar 02, 2015 at 12:01 PM
I just thought I'd mention that we've created an asset on the asset store to perform this function - Font Changer. Our game has a large UI; some objects in the current scene, and many prefabs in the project. We needed a way to quickly and easily change the font throughout the scene and entire project, so we developed the Font Changer. It can also increase/decrease/change the font size through the project & scene too. Hopefully this makes changing fonts in your projects a whole lot easier!
Your answer
Follow this Question
Related Questions
A node in a childnode? 1 Answer
Detecting a UI element is over another UI element 1 Answer
Menu Movements Quetion! 2 Answers
Necromancer GUI doesn't work? 1 Answer
Best practices for ending a game / dying / restarting 0 Answers