Search Unity

TextMesh Pro TMPro "Resources"

Discussion in 'Unity UI (uGUI) & TextMesh Pro' started by dgoyette, Jan 8, 2019.

  1. dgoyette

    dgoyette

    Joined:
    Jul 1, 2016
    Posts:
    2,014
    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?
     
  2. dgoyette

    dgoyette

    Joined:
    Jul 1, 2016
    Posts:
    2,014
    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

    Unity Technologies

    Joined:
    Feb 26, 2017
    Posts:
    3,348
    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:
    359
    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

    Unity Technologies

    Joined:
    Feb 26, 2017
    Posts:
    3,348
    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.
     
  6. Peter77

    Peter77

    Joined:
    Jun 12, 2013
    Posts:
    4,135
  7. Stephan_B

    Stephan_B

    Unity Technologies

    Joined:
    Feb 26, 2017
    Posts:
    3,348
    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:
    19
    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

    Unity Technologies

    Joined:
    Feb 26, 2017
    Posts:
    3,348
    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?
     
    MikeMarcin likes this.
  10. MikeMarcin

    MikeMarcin

    Joined:
    May 15, 2012
    Posts:
    13
    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

    Unity Technologies

    Joined:
    Feb 26, 2017
    Posts:
    3,348
    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.
     
    NamiaLus likes this.
  12. esc_marcin

    esc_marcin

    Joined:
    Sep 30, 2016
    Posts:
    19
    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:
    85
    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.