Search Unity

Unable to reference TextMesh Pro Unity Package from custom DLL

Discussion in 'UGUI & TextMesh Pro' started by astorms, Feb 20, 2019.

  1. astorms

    astorms

    Joined:
    Jan 31, 2018
    Posts:
    50
    Hi everyone,

    I have been searching the depths of forums and banging my head against the wall for 2 days over this hopefully simple issue. I have developed a custom DLL outside of Unity in its own csproj that depends on UnityEngine, UnityEngine.UI, UnityEditor, and TextMesh Pro. However, upon dropping the DLL into a Unity project to use, I get the error:

    Assembly 'MyLibrary.dll' will not be loaded due to errors:
    Unable to resolve reference 'TMPro'. Is the assembly missing or incompatible with the current platform?



    What confuses me is
    1. it has no trouble referencing UnityEngine, UnityEngine.UI, or UnityEditor. I know this because I built a version of my DLL that didn't include the components that referenced TMPro and it worked fine.
    2. other scripts in the Unity project are able to access the TMPro namespace just fine.
    I am on Unity 2018.3.6 with TextMeshPro 1.3.0 from the package manager. I am in a simple test project with nothing else going on, so it is easy for me to try anything.

    Thanks in advanced!!!
     
  2. Stephan_B

    Stephan_B

    Joined:
    Feb 26, 2017
    Posts:
    6,595
    The UnityEngine, UnityEditor and UnityEngine.UI assemblies are built with the Editor whereas the Unity.TextMeshPro assembly is not since it is a package using Assembly Definitions (.asmdef).

    In your project, are you referencing the "Unity.TextMeshPro" assembly?

    It is possible that external assemblies are loaded before the assemblies from packages which would be an issue in this case.

    I am asking the Scripting and Package Manager team and provide feedback once I have more information.
     
  3. astorms

    astorms

    Joined:
    Jan 31, 2018
    Posts:
    50
    Thank you for your quick response. I have more interesting information for you in response to your question:

    In my project I was not referencing the Unity.TextMeshPro assembly (assuming you're talking about the one in the Library -> ScriptAssemblies folder of a Unity project). Rather, I had built a TextMeshPro DLL of my own from the scripts in the Scripts -> Runtime folder of the Unity package (only because at the time I didn't know about the Library -> ScriptAssemblies folder).

    Problem 1: I tried switching the reference in my project to the Unity.TextMeshPro DLL directly, but that created 2 errors in VS Code:
    The type 'Color' is defined in an assembly that is not referenced. You must add a reference to assembly 'UnityEngine.CoreModule'

    The type 'Vector2' is defined in an assembly that is not referenced. You must add a reference to assembly 'UnityEngine.CoreModule'


    Problem 2: To fix Problem 1, I added the reference to UnityEngine.CoreModule.dll, and now my project is flooded with tons of errors like the following:
    The type 'Color32' exists in both 'UnityEngine.CoreModule' and 'UnityEngine'


    I feel like i'm running in circles and really don't know what the problem is.

    EDIT:
    After more reading elsewhere, I know that we should never be referencing UnityEngine.CoreModule directly, so Problem 2 is irrelevant.
     
    Last edited: Feb 20, 2019
  4. astorms

    astorms

    Joined:
    Jan 31, 2018
    Posts:
    50
    Here is more information for you: in my post above I referenced the errors about Color and Vector2. It turns out, it only complains about Color and Vector2 types that exist in TextMeshPro in some fashion (e.g. TMP_Text.color). In other words, I can create my own variable of type Color with no problem upload_2019-2-20_11-12-37.png
     
  5. arnauddc

    arnauddc

    Joined:
    Mar 7, 2018
    Posts:
    1
    I was facing the same problem and instead of referencing "Unity.TextMeshPro.dll" and "UnityEngine.dll", I am referencing "Unity.TextMeshPro.dll", "UnityEngine.CoreModule.dll", "UnityEditor.dll" and plenty of other Unity dlls according to my needs (from UnityInstallationFolder\Editor\Data\Managed\UnityEngine or from MyProject\Library\ScriptAssemblies).
    So I was able to build my dll and use it in other Unity projects.
     
    Kirsche likes this.
  6. Kirsche

    Kirsche

    Joined:
    Apr 14, 2015
    Posts:
    121