- Home /
Assembly Definition + Packages = ?
I have a pretty large project and I'm trying to use the Assembly Definition files to make compilation faster.
With the new Unity package management, I'm using some extensions as packages as recommended. One of them is TextMeshPro.
But now, TMPro can't be found anymore.
Is there any way to make it work?
I found an issue on Unity Issue Tracker that says that it's fixed, but it's really not (or I'm doing something wrong here). https://issuetracker.unity3d.com/issues/cant-add-references-to-package-manager-asmdef-files-from-the-editor
Answer by Lightzer · Jul 12, 2018 at 08:53 PM
I've found the answer here: https://forum.unity.com/threads/use-package-manager-and-assembly-definition-error.520519/
I've tested it, and it works for me. Not happy with the answer, but I guess it works :\
That made it. Well, I updated to version 2018.2.0 also. But the workaround did the trick. Thanks!
Answer by OleJuergensen · Jul 03, 2018 at 01:38 PM
An assembly definition file will cause all script on that folder level and below in the hierarchy to be compiled into a separate assembly. Think of it like a library. All your scripts that are not part of that assembly need an explicit assembly reference to that. I think, the editor already gives you an error messages that asks you, if you forgot an assembly reference. To create such a reference, all your scripts must be in an assembly with an assembly definition file, so that you can actually define references in the first place. Create an assembly definition file for all your scripts (e.g., directly in the assets folder, or in your scripts folder). That will encompass all scripts until a different assembly definition is found in the hierarchy below. Now, if you select your main assembly definition file, you can add references to other assemblies in the editor.
Some tripping stones:
You cannot have cyclic reference. Scripts that depend on each other must be in the same assembly.
References are transitive. That means if assembly A references assembly B, which in turn references assembly C, then you can use scripts of assembly C in assembly A.
Editor scripts must be in a separate assembly that is marked as a test assembly (there is a checkbox in the editor for that). The same goes for tests (duh). This is because you don't want these scripts to be compiled in your final build. These test assemblies will need references to the assemblies of the respective runtime scripts, of course.
When there are editor scripts in different editor folders that reference each other, you are forced to restructure these folders. I find the most viable solution to write a utility that will rearrange scripts and folders accordingly.
When you have many external packages, many editor folders and a bunch of tests, you can end up with dozens of assemblies quickly. Here, I also suggest to restructure your folder structure.
Personally, I think the concept of assembly definition files really needs improvement.
Some references: https://docs.unity3d.com/Manual/ScriptCompilationAssemblyDefinitionFiles.html https://answers.unity.com/questions/1446378/assembly-definition-in-editor-folder.html https://forum.unity.com/threads/example-project-assembly-definition-files.482313/page-4#post-3296568
Hi there,
Well, I know how Assemblies work and that folder restructure you mention, I did it :). The problem here is that Text$$anonymous$$eshPro
now can't be used since it's not an extension with a folder inside the project anymore, it's now a Package (it's really confusing though... extensions, plugins, packages). The same will occur to all packages according to this issue (note that someone there is really impatient hahah)
It doesn't answer my question but it's a very good amount of information. Thanks!
Oh sorry, my bad - should have read your question properly. This just seems to confirm my conception that assembly definition files just aren't production ready just yet. I wonder if it actually is possible to add the reference manually, like suggested in the issue you mentioned. But since you tried and it didn't work, we would need a response from OP or Unity.
Answer by IndividualGamesUnity · Apr 02, 2021 at 01:31 PM
Problem: TMPro namespace is missing, when using TMPro;
Quick Solution: Click on your .asmdef file then in Assembly Definition References tab click on "+" and "add" the Unity.TextMeshPro from the prompt menu.
Explanation: Asmdefs and asmrefs are like chapters of a book. All the chapters need to be under the book so you can read it. You have to add the asmdef of TextMeshPro from the packages like this so your own asmdef will "link" to that codebase.