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?
search for UnityEngine.UI.Text
select them all then change and they all change
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 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.
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!