Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

UI Support

Discussion in 'Editor & General Support' started by jakebaker865, Jun 6, 2020.

  1. jakebaker865

    jakebaker865

    Joined:
    May 6, 2020
    Posts:
    36
    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<int> parentUIDs;
    public List<EditableConversationNode> 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
    }
    }
    }
     
  2. Lurking-Ninja

    Lurking-Ninja

    Joined:
    Jan 20, 2015
    Posts:
    10,005
  3. jakebaker865

    jakebaker865

    Joined:
    May 6, 2020
    Posts:
    36
    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.
     
  4. dgoyette

    dgoyette

    Joined:
    Jul 1, 2016
    Posts:
    4,120
    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?
     
  5. jakebaker865

    jakebaker865

    Joined:
    May 6, 2020
    Posts:
    36
    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.