UI Support

Hi All,

Can anyone help me get rid of UnityEditor.AssetDatabase from my code? It’s causing issues when trying to build. Right now I have the #endif staving off the build errors, but the text isn’t displaying correctly in the build because of this. It’s just trying to pull the TextMeshPro font I believe.

public TMPro.TMP_FontAsset TMPFont;
[DataMember] public string TMPFontGUID;
[DataMember]
public List parentUIDs;
public List parents;
public abstract void RemoveSelfFromTree();
public abstract void RegisterUIDs();
public virtual void PrepareForSerialization()
{
string guid;
long li;
if (TMPFont != null)
{
#if UNITY_EDITOR
if (UnityEditor.AssetDatabase.TryGetGUIDAndLocalFileIdentifier(TMPFont, out guid, out li))
TMPFontGUID = guid;
#endif
}
else
TMPFontGUID = “”;
}
public virtual void Deserialize()
{
if (!string.IsNullOrEmpty(TMPFontGUID))
{
#if UNITY_EDITOR
string path = UnityEditor.AssetDatabase.GUIDToAssetPath(TMPFontGUID);
TMPFont = (TMPro.TMP_FontAsset)UnityEditor.AssetDatabase.LoadAssetAtPath(path, typeof(TMPro.TMP_FontAsset));
#endif
}
}
}

https://forum.unity.com/threads/using-code-tags-properly.134625/ please edit your post!

What exactly those issues are?

I can use an #endif around the assetdatabase to get around the build errors, but what’s happening is that the selected TextMeshPro font that the AssetDatabase is trying to find isn’t there. The font is used for a dialogue system. The system works fine, just no TextMeshPro.

So you need a run-time approach to loading and assigning fonts to objects? Have you considered using the Addressables package to load things at runtime? Do you really need to load things at runtime, or could the fonts just be assigned to the text object in the inspector?

Sorry I’m so late getting back to this. The script I got was from the asset store, and I’m afraid that modifying it would take too much work, so I’ve moved on from this for now.