1
\$\begingroup\$

I'm writing an asset that will be used by many people, but it depends on TextMeshPro (TMP). I ran into a bug in TMP that can only be fixed by upgrading to a preview version. I want to warn users that install my asset that they need to upgrade their TMP version if they are using a prior version. Surprisingly, I can't find this anywhere online or in the docs.

just something like

if (TextMeshPro.version < MyAsset.RequiredTMPVersion) {
    Debug.LogError("Need to upgrade TMP");
}
\$\endgroup\$
1
\$\begingroup\$

I believe you can use Unity's PackageManager.

First you search for the package you need info of (TMP) with PackageManager.Client (I think it will look something like this: var tmp = Client.Search("com.unity.textmeshpro").Result;, be aware that .Result is synchronous, maybe there's a better way to implement this using Tasks).

Then you get the package's info (version) with PackageManager.PackageInfo (something like tmp.version). Done.

|improve this answer|||||
\$\endgroup\$
  • 1
    \$\begingroup\$ The second line needed to be tmp[0].version since the Result is an array. Thanks! \$\endgroup\$ – Adam B Mar 25 at 21:10
  • 1
    \$\begingroup\$ Actually I jumped the gun. The result is null. PackageInfo[] textmeshpro = Client.Search("com.unity.textmeshpro").Result; \$\endgroup\$ – Adam B Mar 25 at 21:17
  • \$\begingroup\$ The result is coming as null? Maybe it's due to the .Result, I didn't see it being used that way in documentation, try an async approach, it might work. \$\endgroup\$ – Diego Penha Mar 26 at 12:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.