Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

TextMesh Pro TMPro "Resources"

Discussion in 'UGUI & TextMesh Pro' started by dgoyette, Jan 8, 2019.

  1. dgoyette

    dgoyette

    Joined:
    Jul 1, 2016
    Posts:
    4,193
    When initially using the package-installed TextMeshPro, it creates a folder of content in my project named "TextMesh Pro". This folder contains a folder named "Resources", which Unity picks up as a "Resources" folder, causing TMPro stuff to be included in my build. It seems inappropriate for packages to use folders named "Resources" given the way Unity automatically treats contents of those kinds of folders in a special way.

    Is there a way to avoid having these assets included in my build?
     
    hamza_unity995 likes this.
  2. dgoyette

    dgoyette

    Joined:
    Jul 1, 2016
    Posts:
    4,193
    It's also worth mentioning that I can't rename the Resources folder within TMP, as it just warns me right after that it needs to import the TMP stuff. (It seems the check that verifies I've imported the TMP assets checks every single file)
     
  3. Stephan_B

    Stephan_B

    Joined:
    Feb 26, 2017
    Posts:
    6,595
    The resources that TMP adds to the local project are truly Essential Resources which TMP needs. These resources must be included in a build otherwise TMP will not work.

    I decided to add these resources to the local project because I wanted to make sure the user was aware and able to manage these resources. These could have been added to some hidden folder but they would still end up part of a build but without the user potentially being aware of it.

    These resources are contained in a Resources folder because the is the only location where resources can be loaded at runtime. Since users can reference these assets by name in the text itself, we need to be able to load these at runtime.

    In terms of managing these resources, the only significant resource is the font asset included in the "Fonts & Materials". The other assets are pretty small on their own. So assuming you create your own font asset and will not use the LiberationSans SDF or even the EmojiOne Sprite Asset then these can be removed / replaced by your own. However, these replacements will still need to be located in a Resources folder and at the location specified in the TMP Settings.
     
    dgoyette likes this.
  4. FiveFingerStudios

    FiveFingerStudios

    Joined:
    Apr 22, 2016
    Posts:
    510
    Is there any plans to move away from the Resources? Unity doesn't recommend using it, and I've noticed that my project in bogged down by third party assets that use the resources folder. It currently takes me 15 seconds to enter play mode (and that's from removing things in the resources folder!). It was over 1 minute to enter playmode before.
     
  5. Stephan_B

    Stephan_B

    Joined:
    Feb 26, 2017
    Posts:
    6,595
    Unless resources are referenced somewhere in the scene or in some prefab, the resources folder is (pretty much) the only location / place that we can load resources at runtime.

    The use of the Resources folder is fine by itself. It does require that you understand that anything included in a Resources folder will be included in a build. So in the case of TextMesh Pro, there are some resources that are required / essential which are those included in the TMP Essential Resources.

    If you create additional font assets or TMP related resources, just be mindful of the fact that if you place those in a resources folder, they will be included in a build. If you are not using those, then move them outside of the resources folder. Keep in mind that if those resources are moved outside the resources folder, you will not be able to access / load them when using the <font> tag in TMP or <sprite> to or whatever other resources you can reference in the text itself.

    Basically, the key is understanding that anything included in a resources folder will be included in a build. So just make sure you don't have unnecessary stuff in there.

    P.S. Resources can be loaded at runtime via AssetBundles but that has other implications as well.
     
    hamza_unity995 likes this.
  6. Peter77

    Peter77

    QA Jesus

    Joined:
    Jun 12, 2013
    Posts:
    6,589
    sama-van, arielfel and JesseSTG like this.
  7. Stephan_B

    Stephan_B

    Joined:
    Feb 26, 2017
    Posts:
    6,595
    I did review your post a while back and started exploring the potential use of a callback.

    The main issue that I ran into is the async aspect of how some of these resources could be loaded which became problematic with resource type tags like <font="Font Asset Name"> or <sprite="Sprite Asset Name">, etc.

    Alternatively, I thought of potentially adding a TMP_ResourceManager where users could register / add resources to the manager which would then enable TMP to use them regardless of where / how they were loaded.

    I am not set on any implementation other than, figuring out some clean / flexible way to allow users to load their resources from AssetBundles, Addressables, Etc.
     
    Last edited: May 11, 2019
    NamiaLus and Peter77 like this.
  8. esc_marcin

    esc_marcin

    Joined:
    Sep 30, 2016
    Posts:
    23
    Any traction on this? It's frustrating to strictly avoid Resources, go through the trouble of using Addressables everywhere and have TMP force Resources upon you in the end anyways.
     
  9. Stephan_B

    Stephan_B

    Joined:
    Feb 26, 2017
    Posts:
    6,595
    I do have an initial implementation of a resources manager for TMP which I referenced in my previous post.

    The main idea is that TMP would no longer load any resources directly but instead rely on the resource manager to provide it with the requested resources (if available). Users would be able to implement their own handling of loading / managing their project resources which would need to be added / registered with the resource manager to make them available.

    This new functionality won't make it into the next release of TMP but most likely in another release not too long after.

    Any thoughts / questions on this?
     
    NotaNaN, Ghetaldus and MikeMarcin like this.
  10. MikeMarcin

    MikeMarcin

    Joined:
    May 15, 2012
    Posts:
    17
    Sounds great. If you could provide a few out of the box resource managers for common use cases it would be even better. Like perhaps a Resources based one for backwards compatibility and a Addressables one for modern projects.
     
  11. Stephan_B

    Stephan_B

    Joined:
    Feb 26, 2017
    Posts:
    6,595
    When a text component requests a resource such as a font asset for instance, the TMP Resource Manager will first check if it has a cached reference to this font asset. If it does not, just like in the current release, it will try to load this font asset from the location specific in the TMP Settings which is "Resources/Fonts & Materials/...". So everything will continue to behave as it did before.

    The main difference will be the ability to add resources to the TMP Resource Manager. So if in your own code, you load a font asset from a Resources folder or Asset Bundle or Addressables or via some other means and then add it to the resource manager then any text component will be able to use it.
     
    FredZvt81 and NamiaLus like this.
  12. esc_marcin

    esc_marcin

    Joined:
    Sep 30, 2016
    Posts:
    23
    I see, I thought you were talking about something like replace all TMP calls to Resources.Load with resourceManager.Load where resourceManager would be an IResourceManger interface with a Load method.

    I'm fine with anything that solves the problem of needing a Resources folder.
     
  13. yakandco

    yakandco

    Joined:
    Dec 3, 2014
    Posts:
    90
    Just chiming in so I can follow along with the progress of this too. Resource folders being used by plugins is a continual source of frustration to me. I wish Unity would remove this antiquated approach. It causes so many issues with console platforms and takes control away from the developer being able to manage when assets are loaded in memory. There are alternatives, I'd take extra boiler plate setup work to manually load assets any day over using them.

    Is there any current way I can remove the shaders and TMP Settings out of Resources? thanks.
     
    faolad likes this.
  14. krisventure

    krisventure

    Joined:
    Mar 24, 2016
    Posts:
    118
    I think the issue here is that I may import and try TextMeshPro and I may still end up not using it in my game at all. If Unity has access to some more advanced "hack" than the average asset developer, I'd hope it could be possible to check for dependencies (in the build scenes and existing Resources folders) and decide at the time we build whether or not to include a package's assets but I understand if this is not possible. Then alternatively, I'll just accept that Unity deems certain assets of its own packages (such as TMPro) small enough to allow it automatically be part of the build even if we don't use it. In this case I'd prefer that you'd place those assets in a hidden folder though rather than a Resources folder because that wouldn't let me accidentally delete / rename the folder like I almost just did it before I found this thread. I'm probably not the only one who has dozens of third party Asset folders from the Asset store because of poor design and at some point before release we systematically go through anything called Resources and rename those folders (after little reflection) one by one to reduce build size. So placing them in a Resources folder has probably more risk than adding a few Kbytes to everyone's build who uses TextMeshPro. A warning instead may be sufficient at the time of build 'Assets required by TextMeshPro (xxx Kb) has been included in your built.' And then if I realize I'm not even using it, I'd just go and uninstall the package and build again.
     
  15. Stephan_B

    Stephan_B

    Joined:
    Feb 26, 2017
    Posts:
    6,595
    If you are not using TMP, the TMP Essential Resources will not be imported in your project and as such will not contribute to it. It you do try out TMP and import the TMP Essential Resources and then for whatever reason decide not to use it, then you can delete the entire "TextMesh Pro" folder and again nothing will be added to your project. Keep in mind the TMP will be the default text system in Unity. It will eventually be renamed and the other text label as legacy as they are no longer on active development.

    Only the content of the Resources folder are included in a build. This folder contains a few asset including the LiberationSans SDF font asset which makes up essentially the bulk of the 2.19mb.

    This font asset is the default font asset used by text object and referenced in the TMP Settings. This default font asset can be replaced by any other user created one and then assigned in the TMP Settings.

    A Resources folder has to be used otherwise, font asset or similar resources could not be loaded at runtime when referenced in the text using either the <font="Name of Font Asset"> tag or other similar tags.

    These resources have to be visible to the user as they can be edited. For instance, in the case of font assets, a user may wish to adjust face metrics, generation settings, fallback list, font weights, characters, glyphs, adjustment pairs, etc.

    Again, if you are not using TMP and have not imported the TMP Essential Resources or TMP Examples & Extras, nothing will be added into your build. If you are using TMP and because these resources are visible, you can remove the resources that you are not using. Again keep in mind that the default font asset LiberationSans SDF is what is contributing 98% of it all.
     
  16. BenHymers

    BenHymers

    Joined:
    Dec 16, 2014
    Posts:
    30
    There's another way to load assets at runtime based on string names - Addressables. I'd love TMP to support Addressables, as it'll let us choose when to load those assets - a great help on console platforms :) Having to load 100s of MBs of font atlases (several fonts, weights, languages - including Chinese with 10k+ characters) on boot, synchronously, is not good - I'd love to be able to do this asynchronously during/after splash screens.

    Do you know when there's likely to be a release implementing the new resource manager you mentioned, @Stephan_B ?
     
  17. Miguel_FirstLight

    Miguel_FirstLight

    Joined:
    Apr 9, 2020
    Posts:
    19
    Hello,

    @Stephan_B do you have an update on the resource manager?
    Do you have an ETA when we will be able to manually load the TextMesh Pro resources via Addressables manually?

    thank you
     
  18. bottledgalaxy

    bottledgalaxy

    Joined:
    Jul 19, 2019
    Posts:
    84
    Just chiming in so I can follow progress on this...
     
  19. Racsoth

    Racsoth

    Joined:
    Feb 20, 2015
    Posts:
    11
    What about renaming the default font file from "LiberationSans" to "Default Font", and to tell devs to override that file with whatever font should be used as default? Given that devs will need to use at least 1 font in their projects, it makes sense to me to allow them to (and direct them to) use that 1 font as their "project default".

    Would that work, or does TMP specifically require LiberationSans in order to work correctly?
     
  20. Stephan_B

    Stephan_B

    Joined:
    Feb 26, 2017
    Posts:
    6,595
    The default font asset is defined in the TMP Settings. As such, you can replace the LiberationSans SDF by any other font asset.
     
  21. Ghetaldus

    Ghetaldus

    Joined:
    Jul 15, 2017
    Posts:
    46
    How it is going with this? Any ETA?
     
    Miguel_FirstLight likes this.
  22. Miguel_FirstLight

    Miguel_FirstLight

    Joined:
    Apr 9, 2020
    Posts:
    19
    Bump
    Is there any information when we might load the default resources via Addressables instead of needing them to be in Resources folder by default?
     
    JesOb and Ghetaldus like this.
  23. JesOb

    JesOb

    Joined:
    Sep 3, 2012
    Posts:
    1,106
    We have issue that all tmp essential resource bundled and loaded into memeory twise once from adressables and second time from resources.

    We need clear way to remove tmp asset from resources and make they loaded from addressables only
     
  24. FredZvt81

    FredZvt81

    Joined:
    Apr 8, 2014
    Posts:
    24
    I'm also looking to use Addressables instead of Resources to load TMP dependencies. As I see on https://docs.unity3d.com/Packages/com.unity.textmeshpro@2.1/changelog/CHANGELOG.html this was still not implemented in the latest version (2.1.3).

    Any estimate on when are we going to have this available?
     
  25. PigletPants

    PigletPants

    Joined:
    Sep 19, 2019
    Posts:
    23
    I just ran into this problem myself. It seems unavoidable to have 2 copies of the sdf font asset in memory with my current setup. My boot scene has menus and appears to use the resources version of the asset. Other addressable scenes with menus are loaded additively and they loading the sdf font asset from their asset bundle.
     
  26. nindim

    nindim

    Joined:
    Jan 22, 2013
    Posts:
    130
    Hi @Stephan_B , We are making the switch to Addressables and found this thread when looking for a way to prevent data duplication related to the TMP Resources assets. Did the resource manager you mentioned make it into a release yet or is it still on the roadmap? Thanks a lot!
     
  27. Stephan_B

    Stephan_B

    Joined:
    Feb 26, 2017
    Posts:
    6,595
    Not in the release yet but most definitely on the roadmap.
     
  28. nindim

    nindim

    Joined:
    Jan 22, 2013
    Posts:
    130
    Thanks a lot for the quick reply, Stephan.

    Good to know this is still happening and it hasn't died as this change will be very valuable.

    I'm currently working through all of our duplicate data caused by the move to Addressables and am getting quite close to the point where it will likely just end up being the TMP data that remains. No doubt my OCD will begin to twitch at that point! :)

    All the best,

    Niall
     
  29. Miguel_FirstLight

    Miguel_FirstLight

    Joined:
    Apr 9, 2020
    Posts:
    19
    Bump for an update for this feature.
    We really need it
     
    JesseSTG and JesOb like this.
  30. JesseSTG

    JesseSTG

    Joined:
    Jan 10, 2019
    Posts:
    236
    Join the club. This would considerably simplify development for certain platforms.

    Is there a way we can fake it with
    UnityEngine.ResourcesAPI
    , at least?
     
  31. Miguel_FirstLight

    Miguel_FirstLight

    Joined:
    Apr 9, 2020
    Posts:
    19
    Bump for an update for this feature.
     
    Feelnside, vsokolenko and JesseSTG like this.
  32. Feelnside

    Feelnside

    Joined:
    Sep 30, 2016
    Posts:
    83
    Also having an issue with TMP Settings resources duplication when using Addressables. Would be great to resolve that issue.
     
  33. OndrejP

    OndrejP

    Joined:
    Jul 19, 2017
    Posts:
    303
    I think we don't need fancy ResourceManager which would do something complicated.
    A simple "TMPResourceLoader" would be enough (then we can implement our own resource manager if needed).

    Code (CSharp):
    1. public class TMPResourceLoader
    2. {
    3.     public static TMPResourceLoader Instance = new TMPResourceLoader();
    4.  
    5.     public virtual TMP_Settings LoadSettings()
    6.     {
    7.         return Resource.Load<TMP_Settings>("...");
    8.     }
    9.  
    10.     public virtual xxx LoadFont(string name) {...}
    11.     public virtual xxx LoadEmoteAtlas(string name) {...}
    12.     // ... etc more methods
    13. }
    That's all. We can inherit our own loader, instantiate it and assign it into `Instance`.
    It can be used with Addressables, AssetBundles, settings could be stored in scene, in preloaded assets, even created at runtime from StreamingAssets.

    The TMP_ResourceManager could be built on top of that, but I think it's essential to have a way to "intercept" the loading call.

    EDIT:
    I end up using ResourceAPI.overrideAPI. When starting the game, I'm loading 'common' asset bundle, which contains assets which are always needed (even in main menu). After this bundle is loaded, I get TMP_Settings asset from the bundle and store it in static variable. Then I return it from ResourcesAPI. Works nicely. Would be better if there's direct callback from TMPResourceLoader, but it's not much big difference.

    The bundle is loaded from [RuntimeInitializeOnLoadMethod(BeforeSceneLoad)]
     
    Last edited: Jul 31, 2021
  34. fendercodes

    fendercodes

    Joined:
    Feb 4, 2019
    Posts:
    191
    Bump. I don't need assets like LiberationSans SDF or EmojiOne in my build. Can I just delete those from the Resources folder? Would prefer if TMP didn't add those in a Resources folder. They'll get referenced when they actually want to be used by a developer and so would be included in builds that way.
     
  35. uwdlg

    uwdlg

    Joined:
    Jan 16, 2017
    Posts:
    142
     
  36. fendercodes

    fendercodes

    Joined:
    Feb 4, 2019
    Posts:
    191
    Why do we need to put our own assets into a Resources folder? I don't mind it, but I cannot think of one other Unity asset that forces us to do that. Shouldn't it just get added to a build automatically because of being referenced by a TMP_Text inspector field?
     
  37. Stephan_B

    Stephan_B

    Joined:
    Feb 26, 2017
    Posts:
    6,595
    You only need to add those TMP Resources in the resources folder location defined in the TMP Settings if you are trying to reference these in the text itself. For instance, something like "A <font="Impact SDF">B" where since the Impact SDF font asset is not referenced by an object but instead in the text, it needs to be included in a resources folder.

    In terms of LiberationSans SDF and its fallback, this is the default font asset assigned in the TMP Settings. If you were to assign your own font asset as Default, you could then remove that font asset. Same for EmojiOne.