As the title says.
Is there any way to replace Font A for Font B in Textmesh pro without going thru all of the texts?
Happen to start with one font then I discovered the font I really need… and it’s a lot of TMP_Text around.
Thanks!
As the title says.
Is there any way to replace Font A for Font B in Textmesh pro without going thru all of the texts?
Happen to start with one font then I discovered the font I really need… and it’s a lot of TMP_Text around.
Thanks!
By all the text, do you mean all text objects in a scene or prefabs in a project?
@Stephan_B Well usually in a scene. I’m thinking if there is a tool like the one used to migrate from the old Textmesh Pro to the new one included in Unity.
So an Editor tool that would manage font asset assignment on text objects referenced in scenes files potentially?
Can you provide more insight on your use case?
@Stephan_B Well I think is simple, I worked on a UI with some font using Textmesh Pro to later find out that there was other font that fits more with the theme… so I have to go over all the scene TMP texts and change the Font by hand… About the tool I remember when migrating from the old TMP there is this tool called
“Project Files GUID Remaping Tool” that will scan all assets using TMP and updating to use the latest version.
So I thought maybe something on that line?
Thank you for providing this additional insight.
Unfortunately, there is no such tool currently available.
Now depending on the number of scenes / text objects you would have to update, it might be worth creating such a tool.
I would suggest taking a look at the TMP_PackageUtilities.cs source code which contains most of the functionality you would need.
The steps would be roughly as follows:
(1) Scan the project to find scene files.
(2) Get the GUID of the current font asset and its replacement.
(3) Read the scene file to find and replace references of the GUID of the current font asset by its replacement. This is what the line looks like in the Scene file.
m_fontAsset: {fileID: 11400000, guid: 8f586378b4e144a9851e7b34d9b748ee, type: 2}
(4) Now if the text object is using material presets, that would add another layer of complexity as you would need to also replace that as well. This is what the material line looks like
m_sharedMaterial: {fileID: 2180264, guid: 8f586378b4e144a9851e7b34d9b748ee, type: 2}
Notice how they are using the same guid. This is because this material preset is actually a sub object of the font asset. Now if this was a separate material, it would have a different guid. You will need to look at a few scene files to figure out how best to handle the potential material preset swap.
P.S. If I had the time, I would implement this but I am far too busy. If this is something you don’t have time or desire to implement, you might be able to get someone from the community here to implement it as this is likely something that would be of value to other TMP users.
Not sure if anyone still needs this, but I made something quick by duplicating and modifying the code in the TMP_PackageUtilities.cs that @Stephan_B mentioned. It won’t handle material presets just looks for the guid of the font asset and replaces it with which ever one you select. Put this script in an editor folder and it should show up in the Window → TextMeshPro → Project Font Replacement Tool.
Thanks for posting this, it does a great job and I’ve found it very useful ![]()
It does not work if the object is not a prefab and is in hierarchy can you do something @jcuriel_glu_1
Thank you so much for your awesome script. Saved me a lot of tedious work in trying out different fonts across an entire project. Seriously, I hope the Unity Team adds your script to Unity itself.
Use this if you are simply going to replace the font of the TMP placed in the scene.
here’s super simple and amazing script. Simply put the script in the inspector, specify the font you want, and press the button.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using TMPro;
#if UNITY_EDITOR
using UnityEditor;
#endif
/*
https://bonnate.tistory.com/
Insert the script into the game object
insert the TMP font in the inspector
and press the button to find and replace all components.
It may work abnormally, so make sure to back up your scene before using it!!
*/
public class TMP_FontChanger : MonoBehaviour
{
[SerializeField] public TMP_FontAsset FontAsset;
}
#if UNITY_EDITOR
[CustomEditor(typeof(TMP_FontChanger))]
public class TMP_FontChangerEditor : Editor
{
public override void OnInspectorGUI()
{
base.OnInspectorGUI();
if (GUILayout.Button("Change Font!"))
{
TMP_FontAsset fontAsset = ((TMP_FontChanger)target).FontAsset;
foreach(TextMeshPro textMeshPro3D in GameObject.FindObjectsOfType<TextMeshPro>())
{
textMeshPro3D.font = fontAsset;
}
foreach(TextMeshProUGUI textMeshProUi in GameObject.FindObjectsOfType<TextMeshProUGUI>())
{
textMeshProUi.font = fontAsset;
}
}
}
}
#endif
8721246–1179255–TMP_FontChanger.cs (1.2 KB)