Search Unity

TextMesh Pro Using TextMeshPro with AssetBundles and runtime TMP_FontAsset.CreateFontAsset

Discussion in 'UGUI & TextMesh Pro' started by Ivan_K_, Jan 19, 2021.

  1. Ivan_K_

    Ivan_K_

    Joined:
    Jun 3, 2019
    Posts:
    4
    We are using AssetBundles for all resources in our project. TMP works well with AssetBundles except one momemt: we are using TMP_FontAsset.CreateFontAsset to create dynamic font from system's one at runtime and CreateFontAsset invokes Shader.Find in ShaderUtilities, which doesn't work with shaders from AssetBundle. This force us add shaders to both build and AssetBundle.

    It would be greate to add overload for CreateFontAsset to pass Shader as a parameter.
     
  2. Stephan_B

    Stephan_B

    Joined:
    Feb 26, 2017
    Posts:
    6,595
    Can you provide more information on how your bundles are setup in regards to TMP resources? Since you are creating dynamic font assets at runtime from OS fonts, what is actually contained in the bundle? Just the shaders?

    Just trying to get a better understanding of your workflow and how you have things working.
     
  3. Ivan_K_

    Ivan_K_

    Joined:
    Jun 3, 2019
    Posts:
    4
    Bundle contains main font, shaders, materials. At runtime we load OS fonts and add them as fallback to main font from bundle.
     
  4. Stephan_B

    Stephan_B

    Joined:
    Feb 26, 2017
    Posts:
    6,595
    So the issue is simply due to the fact the shaders are not included in the build whereas such you they are not found when you create those dynamic font assets. Correct?

    You do not include the shaders in the build because they are essentially duplicated by the fact the bundle pulls them in as dependency of the font asset material. Correct?

    Can't the shaders be accessed from the bundle and then just after you create the dynamic font asset which ends up with a missing shader, manually assign the shader from the bundle?

    Just trying to get a full understanding so the right solution can be implemented on my end.
     
  5. Ivan_K_

    Ivan_K_

    Joined:
    Jun 3, 2019
    Posts:
    4
    Yes.

    Yes.

    API Shader.Find doesn't work with shaders in bundle, so Material's contructor throw NullReferenceException due to missing Shader during CreateFontAsset. So we want manually load shader from bundle and pass it to CreateFontAsset.