Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Detecting TextMesh Pro

Discussion in 'UGUI & TextMesh Pro' started by Anoril, Oct 4, 2019.

  1. Anoril

    Anoril

    Joined:
    Sep 24, 2013
    Posts:
    4
    Hi,

    I'm developping a plugin that may use TextMesh Pro. But I want a fallback if TMP is not available. Like common Text component.

    How can I detect TMP presence in Unity?

    Usually, I check for preprocessor directives like "#if MY_COMPONENT ..." but I can't figure out if such a mecanism is available from withing TMP.

    Anyone as a solution?

    Best regards,

    Paul
     
    Siccity and TomTrottel like this.
  2. Stephan_B

    Stephan_B

    Unity Technologies

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

    Anoril

    Joined:
    Sep 24, 2013
    Posts:
    4
    Hi,

    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 ^_^

    Any "other" solution?
     
    Siccity likes this.
  4. TomTrottel

    TomTrottel

    Joined:
    Aug 16, 2014
    Posts:
    18
    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 :(

    Did you find a way ?
     
  5. Siccity

    Siccity

    Joined:
    Dec 7, 2013
    Posts:
    255
    Still looking for a solution
     
  6. andyz

    andyz

    Joined:
    Jan 5, 2010
    Posts:
    2,133
    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)
     
  7. Stephan_B

    Stephan_B

    Unity Technologies

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

    upload_2021-4-23_2-53-42.png

    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.
     
    ryan-at-melcher, lincolncpp and andyz like this.