Search Unity

TextMesh Pro Check if TextMesh Pro is present in project

Discussion in 'UGUI & TextMesh Pro' started by Johannski, Jul 1, 2018.

  1. Johannski

    Johannski

    Joined:
    Jan 25, 2014
    Posts:
    826
    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?
     
  2. Stephan_B

    Stephan_B

    Joined:
    Feb 26, 2017
    Posts:
    6,595
    I used to add the "TMP_PRESENT" to the global defines in OnInitializeOnLoad() but was never satisfied with that handling so I removed it.

    The ability to add global defines for package is something that is being looked into as it is a common request. I proper solution is in the works.
     
    Hosnkobf likes this.
  3. Johannski

    Johannski

    Joined:
    Jan 25, 2014
    Posts:
    826
    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.
     
  4. seizestudios

    seizestudios

    Joined:
    Oct 18, 2016
    Posts:
    24
    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.
     
  5. io-games

    io-games

    Joined:
    Jun 2, 2016
    Posts:
    104
    Bump
     
    eskivor likes this.
  6. Kronnect

    Kronnect

    Joined:
    Nov 16, 2014
    Posts:
    2,905
    Still no macro?
     
  7. AmyGilhespy

    AmyGilhespy

    Joined:
    Mar 7, 2019
    Posts:
    10
    Bump
     
    eskivor likes this.
  8. Stephan_B

    Stephan_B

    Joined:
    Feb 26, 2017
    Posts:
    6,595
    You should be able to check for the presence of the TMP package via the Package Manager API.
     
  9. Kronnect

    Kronnect

    Joined:
    Nov 16, 2014
    Posts:
    2,905
    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
     
    eskivor likes this.
  10. cecarlsen

    cecarlsen

    Joined:
    Jun 30, 2006
    Posts:
    862
  11. VrGamesDev

    VrGamesDev

    Joined:
    May 7, 2018
    Posts:
    65
  12. Siccity

    Siccity

    Joined:
    Dec 7, 2013
    Posts:
    255
    Any update on this?
     
    eskivor likes this.
  13. Stephan_B

    Stephan_B

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

    upload_2020-12-16_13-4-13.png

    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.
     
    Last edited: Dec 16, 2020
  14. Siccity

    Siccity

    Joined:
    Dec 7, 2013
    Posts:
    255
    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.

    upload_2021-11-17_10-21-2.png
     
  15. HyeroDrimm

    HyeroDrimm

    Joined:
    Jan 18, 2020
    Posts:
    4
    Still nothing?
     
  16. Stephan_B

    Stephan_B

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

    a436t4ataf

    Joined:
    May 19, 2013
    Posts:
    1,933
    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.
     
    Last edited: Jan 21, 2024