Is there a way to check if TMP is present in a project? The question is regarding to assets for the asset store that want to support TMP, but only if it is present.
Is there a script define smybole, or should we check if a class exists and then establish our own script define?
Ah okay, so I do remeber this correctly. Thanks for the answer, I guess as of now it is best to just deal with an extra download to support TMP or just create an own script define. Thanks, looking forward to the streamlined solution.
Hello guys!
Are there any updates on this issue?
I’m now searching for assemblies and adding my own compile condition. And that kind of sucks…
A TMP native way would be great.
Hello Stephan,
Does the API work in a build or only in Editor?
We need a compiler macro to ensure certain code TMP-dependant only compiles if TMP is present, otherwise it will throw errors.
Do you have perhaps a short snippet we can use to detect TMP safely?
Thanks
Assuming you are using Assembly Definitions in Unity 2019.4 or newer, you can use the Version Defines feature to define in your own “define” for TMP.
To do this, you would edit your assembly definition (.asmdef) which for this example is called “MyAssemblyDefinition”.
Once this is done, you can then use that version define in any of the scripts in your assembly where if the “com.unity.textmeshpro” assembly is present it will be true. In this example, I used version 1.0.0 but you could revise this to check for a specific version of the TMP package such as 1.5.3-preview.0.
Since TMP is included by default with the Editor, the package will pretty much always be present but that doesn’t mean the user is using TMP or has imported the TMP Essential Resources. But for that you can simply check for the present of the “TextMesh Pro” folder in the project or if the TMP Settings are present in the project.
Please let me know if this is a workable solution for your use case.
Hello. Assembly Definition defines would be a great solution if only it was actually set up in TMP. But I can see that it’s not. This is a problem for assets that aim to be plug-and-play, which is what this thread is all about.
In your own assembly definitions, you can add a version define as per the following docs.
Note that TMP is a default package which means it is pretty much always present. However, that doesn’t mean that a user is using it. Checking if the TMP Essential Resources are present in the project would be a better indication of that.
EDITED: actually this appears to have been a UnityEditor bug - something in asmdefs got corrupt, restarting the UnityEditor … and it built correctly! Sorry for the noise.