what do each of these do when imported into a new project?
Dependencies on a package.json, are meant to be resolved by the PackageManager
. If propperly configured, when installing a package that depends on other packages, those dependencies will be installed along with the package:
eg: You have “MyCustomPackage
” that depends on “Unity.VisualEffectGraph
” package. When installing “MyCustomPackage
” the package manager will also download and install “Unity.VisualEffectGraph
” (if its has not already been added). You also have versioning syntax that allows to specify compatible version ranges for dependencies.
On the other side, for an Asmdef, you are directly telling you package code Assembly, which other Assemblies it needs for it to compile propperly. Those are not managed or auto-imported by anything, they must be properly setup by you.
eg: using the previous example. If you need to reference code from Unity.VisualEffectGraph
in the code of your package, your Asmdef will have referenced the Asmdef inside the Unity.VisualEffectGraph
package.
One thing to be carefull here is the “use GUIDs” flag. Normally, Asmdefs inside “Packages/…” will come with no “.meta” files. That means, that the GUID for the referenced Asmdef will be different for each user that uses the package. This is not exactly always the case, for a variety of reasons, but for packages is better practice to never check the “use GUIDs” flag, so it gets serialized by name, instead of by asset guid.
If you are missing a reference inside a Asmdef, and your code is actually using a member of the “missing” assembly, then it will throw an error and wont compile.
On the other side, if a package dependency is missing or cannot be resolved, i dont remember if it may not let you install the package, or maybe install it but depending on “what” is missing, a variety of errors could happen. (you could have a package setup as a dependency, but neither your code nor any asset is directly using it, so it may not give any errors, this really depends on the case)
A related question, does the naming of the asmdef matter? Does it need to align with the namespace you’re using or your package name?
Ideally YES. This is more for debug & organization purposes. but it is usefull that your Asmdef asset name, is exactly the same name as the “Name” field.
It is also recommended to have a “Root Namespace” also properly setup, but it’s currently just used when manually creating a new Script on the Editor. The template used for the new script will automatically have the root namespace of its containing assembly .