Search Unity

My scripts is not visible to Packages. Is there a walk around?

Discussion in 'Package Manager' started by YoungXi, Dec 27, 2019.

  1. YoungXi

    YoungXi

    Joined:
    Jun 5, 2013
    Posts:
    63
    So, I've downloaded the TextMeshPro(v1.4.1) package, and I moved the source into my 'Assets/' folder.
    And I noticed that I can't access to any of my code under 'Scripts' folder.

    TextMeshPro uses asmdef file to seperate itself into different dll.
    https://docs.unity3d.com/Manual/ScriptCompilationAssemblyDefinitionFiles.html

    So I wonder, is it still possible to access my scripts in any other packages? I know that sounds strange, but I need to modify the codes in TextMeshPro, and I've tried to delete those asmdef files, it didn't work : encountered other errors: UnityEngine.TextCore.LowLevel.GlyphValueRecord became no more accessible for TMP...

    So if no one knows how to resolve this issue, I'm just gonna have to inherit TextMeshPro instead of modify it directly...
     
  2. Favo-Yang

    Favo-Yang

    Joined:
    Apr 4, 2011
    Posts:
    464
    • Install TMP through package manager
    • Move the new added folder from Library/PackageCache to Packages
    • Edit the Packages/manifest.json, remove tmp from reference
    • Start hacking the source code
    Will this work for you?
     
    karl_jones likes this.
  3. YoungXi

    YoungXi

    Joined:
    Jun 5, 2013
    Posts:
    63
    Hi, that's exactly what I did. I mean, I can do any change to the source code, except trying to access to other classes defined in global namespace in my scripts folder.

    I believe those scripts are under Assembly-CSharp, while TMP remain in a separate assembly because of asmdef.
     
  4. Favo-Yang

    Favo-Yang

    Joined:
    Apr 4, 2011
    Posts:
    464
    Well, you answered the question yourself. Scripts outside Assets path (i.e. Packages/<package-name>), are required to create an Assembly Definition Asset in a folder, to compile into a separate managed assembly. All package assemblies are compiled before the Assembly-CSharp, therefore it's not possible for the TMP package to reference scripts in Assembly-CSharp.

    Opt 1, refactor you code to pull another package, i.e. package-shared. Change the asmdef file of TMP package to reference the new package asmdef. This is a common practice to solve the reference issue.

    Opt 2, move the TMP folder to Assets, delete the asmdef file so all codes are compiled into the Assembly-CSharp. But it may slower the compiler because of those TMP scripts.

    References
    - https://docs.unity3d.com/Manual/ScriptCompilationAssemblyDefinitionFiles.html
    - https://docs.unity3d.com/Manual/cus-asmdef.html
     
  5. YoungXi

    YoungXi

    Joined:
    Jun 5, 2013
    Posts:
    63
    Hi, thanks for your advices!

    Opt 1, currently not possible for the project...
    Opt 2, tried, and I got some errors from TMP after I removed those asmdef files... TMP references internal class in UnityEngine.dll, and after I removed the asmdef file, it started to give me undefined symbols...

    So, my final solution is: Inheritance... I inherited from TMP class, and put my custom code in the derived class...
     
    Favo-Yang likes this.