Issues using package scripts when importing as package instead of asset package

Hello,

I have an existing asset package that was created via exporting from a project (.unitypackage) as described on the unity docs page here. I am trying to “convert” this package to a custom package that can be imported by package manager per the very first line on that page which recommends doing so via the custom package process described here. I am using Unity 2020.3.30f1. The package contains some dependent library files, a few scripts, a sample prefab and a sample scene

As a .unitypackage, the package imports its contents to Assets/ and the sample scene, prefab and scripts are all useable with no issue. When importing via the UPM (selecting the package.json file) all the package contents are added to Packages/. All the expected files are present and no errors appear in the console after the import.

The issue arises when I try to use any of the package contents in the project itself. When attempting to attach a script from the package to a scene object (even when copying the script to Assets/ first) I receive a “script class cannot be found. Make sure there are no compile errors and that the file name and class name match” error despite there being no compile errors and the names indeed match.

Could anyone help me understand why the package contents are unusable in this way and what I might need to do to achieve a similar result as when importing using .unitypackage? Is there even a point to trying to make a custom package as Unity recommends here or am I just wasting my time?

Not exactly answering your question, but here is a good thread explaining UPM packages:

Thanks for sharing that! An excellent dive into package creation I especially love the suggested repo directory structures. I’ll peruse through and see if any recommended changes impact my current issue. For the moment, it persists :frowning:

Please check that you’ve created an Assembly Definition file in your UPM package.

Hi again, I’m happy to say I’ve finally got things working well in the custom package version. The link you shared was incredibly helpful because until that point I hadn’t found anything that spoke about both types of packages side-by-side like that. My asmdef files weren’t quite right and I did not have the package’s resources/dependencies organized correctly either. And beyond that now it is much clearer to me how a package repo should be organized to most easily support many unity versions. Really great stuff, thanks for taking the time to share it with me.