TextMesh Pro is included by default in Unity since 2018.x. That doesn’t mean that a user is using it by the core of TMP is always present. Since anyone using TMP has to import the TMP Essential Resources which are always located in the “TextMesh Pro/…” folder, you can specifically check if that folder and one of the core essential resources like the TMP Settings.asset is present in the project. This would most certainly indicate the TMP is in use.
Thanks Stephan, but
1/ I’m using 2019.1.6 and TMP is not present; checking the PackageManager, I would be able to install it by selecting the package and click “install”, but why do so if I do not have need of TMP. The core do not seems to be present as when I write “using TMP” in my C# code, this line goes red and a message “The type or namespace name `TMPro’ could not be found. Are you missing an assembly reference?” is displayed.
2/ It is not possible to check for folder structure from the code not in run time, thus it would be a pain to make a dynamic code that compiles at runtime
I don’t want to make two plugins, one for who is using TMP and one for the others, and I don’t want to restrict my plugin to users using TMP
I must be an old fashion programmer by asking for code directives, but I feel weird that it is not possible to identify facultative content from a piece of code
Anoril I have have the same desire, since I want to make installing TextMeshPro optional for a little framwork I am working on. But without a compiler directive or something else, this is a bit … impossible cause as soon I am using
“using TMPro;” there will be an error messge
This is an issue I noticed in a major asset-store plugin.
If TMP is included in a project but not ‘really’ used, what is the downside - an increased code size, more assets?
TMP really needs to be properly integrated with the UI package OR be a detectable add on
(Great asset - too long ignored in terms of integration)
Neither as a result of code stripping. However, if the TMP Essential Resources are imported in the project, you will then get those few resources included in the Resources folder included in the build.
In terms of detecting TMP, there is no easy way for me to set that up on the package side other than adding a global scripting define. However, if your project or AssetStore asset uses assembly definitions, it is possible to add a Version Define to your .asmdef as seen below.
Therefore, in the case where a version of com.unity.textmeshpro is present with version 4.0.0-preview.0 or greater, the “TEXTMESHPRO_4_0_OR_NEWER” would be defined. Again, this version define is setup in your own assembly definitions.