Addressables usage within a package

How does one utilize an addressable group stored in a package? I would assume you could just add the group to the main project’s addressable group list, but I can’t seem to make that work.

I have two projects.

  1. An embedded package and some testing files. The package has all assets set up in addressables.
  2. A game project using the other project as a local package.

Importing the local package works almost perfectly… the addressable data is missing and I have so far failed in fixing it.

As an ancillary question, is it a good idea to utilize a hopefully self-contained addressables group within a custom package?

Well progress towards something almost useful.
https://docs.unity3d.com/Packages/com.unity.addressables@1.16/manual/AddressableAssetsGettingStarted.html

Specifically:
Assets in Packages

Important: Marking package assets as Addressable requires Unity version 2020.2.0a9 or later.
Creating Addressable Groups in packages

Create a group in the Addressables Groups window. When you are done modifying the group, save the project. Move the group asset and its respective schema assets into your package.

Open a new project that uses your package. If your group has a “Content Packing & Unloading” schema, update its build and load paths. Your group can now be included in your next Addressables build.

If you want to modify the group again, make sure to close all projects that use the package and reopen them once you save all modifications. This will reload the group asset. If your group has a “Content Packing & Unloading” schema, update its build and load paths again.

Not sure if I’ve been looking at the wrong versions of everything, but that chunk of information was incredibly hard to find, and slightly confusing. I did not know what to expect, and it took me a bit to realize that there is an option in the build/load paths matching the package I’m trying to pull addressable data from.

It’s still not properly loading any of the assets from the package’s addressable groups, but I at least feel like I’m one step closer.

I’m super confused. One time I was able to choose an option matching my package for the build/load paths of an addressable group. Now I can’t.

I created a new blank addressable group, added the “Content Packing & Loading” schema, chose the matching option for Build Path and Load Path, tried to play scene, and found it still broken. Realized I was using an old sample scene that needed replaced, deleted it, imported new sample scene, tried to play scene, and found it still broken but throwing weird “TLS Allocator” exceptions. Saved project out of habit, rebooted the editor to fix the “TLS Allocator” exceptions successfully, and found I was getting “InvalidKeyException” from addressables. Double checked things I knew how to check, and realized I could no longer use the matching option in the existing group or a new group.

I have no clue, like literally no clue.

Verified that both the Package and Project were in Unity 2020.2.5f1, and were using Addressables 1.16.16.
I deleted and created a new Addressables settings file in my project.
I glanced through the settings of all the files that step generated, no clue if I changed anything.
I removed and re-added my local package.
Didn’t even rebuild the addressables groups.
It works.

Something, this time through, auto-imported the addressables group contained in my package. Absolutely no clue how.

Attempted to import package into a different project to see if I could hammer out why I struggled. I believe it came down to Order of Operations.

  1. Open project you wish to import a package into that has an Addressables group stored in it.
  2. Import Addressables package if not already in project.
  3. Create Addressables settings if not already existing.
  4. Import package with Addressables group.

That’s it.

I have a local project referencing a local custom package, both in Unity 2020.2.5f1 using Addressables 1.16.16. The above steps caused the Addressables group in the custom package to be automatically imported.

If you import the package with an Addressables group before you create the settings, and desire to manually hook up the group which didn’t automatically become accessible… good luck. I never figured out how.

I do not know if my slew of updating through different Unity versions / Addressable versions, or any of the myriad of changes I made through my struggles got me to the point where it was that simple. But something finally worked and is repeatable.

2 Likes

Thanks for posting your progress!

I followed these last steps, and even though the Group shows up in the Addressables group, the schema still seems to point to the source project’s BuildPath and LoadPath IDs.

The docs say > “If your group has a “Content Packing & Unloading” schema, update its build and load paths”.

But I have no idea what that means. This schema is in an immutable folder, imported from the package. So as best as I can tell, it’s always going to point to a bogus BuildPath lookup.

Were you actually able to get these package-inherited addressables to be included in a build?

Edit1: I’m mainly looking for feedback from Unity on this, not really asking for you ( @berycs ) to keep digging if you’ve got it working.

Edit2: Here’s a link to a package that includes an AddressablesGroup and Schema: GitHub - erowe-imangi/unity-package-with-addressable-example: An empty package that includes an Addressables Group to test including Addressables in packages in Unity 2021

Same problem here.

In the test project that has imported my package and the addressables package as a dependency, I get this error.

TargetException: Non-static method requires a target.
System.Reflection.MonoMethod.Invoke (System.Object obj, System.Reflection.BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[ ] parameters, System.Globalization.CultureInfo culture) (at :0)
System.Reflection.MethodBase.Invoke (System.Object obj, System.Object[ ] parameters) (at :0)
UnityEngine.AddressableAssets.AddressablesImpl.InitializeAsync (System.String runtimeDataPath, System.String providerSuffix, System.Boolean autoReleaseHandle) (at Library/PackageCache/com.unity.addressables@1.16.16/Runtime/AddressablesImpl.cs:413)
UnityEngine.AddressableAssets.AddressablesImpl.InitializeAsync () (at Library/PackageCache/com.unity.addressables@1.16.16/Runtime/AddressablesImpl.cs:433)
UnityEngine.AddressableAssets.AddressablesImpl.get_ChainOperation () (at Library/PackageCache/com.unity.addressables@1.16.16/Runtime/AddressablesImpl.cs:130)
UnityEngine.AddressableAssets.AddressablesImpl.LoadAssetsAsync[TObject] (System.Object key, System.Action1[T] callback, System.Boolean releaseDependenciesOnFailure) (at Library/PackageCache/com.unity.addressables@1.16.16/Runtime/AddressablesImpl.cs:643) UnityEngine.AddressableAssets.Addressables.LoadAssetsAsync[TObject] (System.Object key, System.Action1[T] callback) (at Library/PackageCache/com.unity.addressables@1.16.16/Runtime/Addressables.cs:685)
FileLoaders.AddressablesManager.Start () (at /Users/REDACTEDMYPROJECT /Scripts/FileLoaders/AddressablesManager.cs:15)

Loading code:

    public class AddressablesManager : MonoBehaviour {

       
        void Start() {
            AssetLabelReference key = new AssetLabelReference() {
                labelString = "Samples"
            };
            Addressables.LoadAssetsAsync<TextAsset>(key, null).Completed += LoadedSamples;
        }
       
        void LoadedSamples(AsyncOperationHandle<IList<TextAsset>> obj) {
            Debug.Log(obj.Result);
            IList<TextAsset> samples = obj.Result;
            foreach (TextAsset sample in samples) {
                Debug.Log(sample.name);
            }
        }

Screenshot of addressables groups in my main project

screenshot of package folder structure

6947096--816980--Screen Shot 2021-03-17 at 9.20.31 PM.png

It loads them in main project fine. But above error in the test project. Here’s what my folder looks like:

Update: If in the new project you generate an addressables settings file, open the addressables groups window, and drag the package’s group asset into that window, it suddenly works.

Surely this is not how it’s supposed to work!? I can’t expect users of my package to fiddle with this stuff every time they want to use it.

Am I missing something obvious here?

EDIT: Further searching found this discussion Addressables in Custom Packages?

meaning in new project generate settings, then reimport package. Definitely not ideal… but there you have it.

Howdy all! I’m going to kick this one over to the team for some insight.

1 Like

Hi all we will update the docs to be less confusing. In general the setup is built with the assumption that the customer is familiar with the Addressables UI, but based on the feedback we will investigate how to make these steps automated.

As described above there are two ways to import the package group asset:

  • Importing the package after Addressables is installed and the Addressables Settings object is created will allow the package group to be automatically referenced by Addressables.
  • Importing the package before Addressables is installed and the Addressables Settings object is created requires manually adding the group (i.e. dragging and dropping the group asset into the Addressables Groups window).

Additionally if the package group has a “Content Packing & Unloading” schema, its build and load paths need to be manually modified to reference the new project. This is important because the paths are serialized as GUIDs which can vary by project. Otherwise they will still refer to the old project and will not translate to valid paths, so loading any assets from the group will fail.

However as noted above, it is not possible to modify the schema asset if the package is immutable-- this is an issue that we can fix by making this step automated.

This is great news that you’re looking into this issue. It seems like a requirement if addressables should be used for shared code/assets.

one similar issue is when you import a package dependent on textmeshpro, you also have to reimport the package if you generate the “essentials” folder afterwards.

This seems to me like a general issue with how the package manager handles dependencies. It might worthwhile to look into how to solve all these types of issues. Maybe something like when an addressables settings is created it scans the entire project and auto adds groups. And maybe when a package is imported with addressables listed as a dependency this automatically triggers a creation of a settings file or at the very least prompts the user to do so. Then that triggers the settings. Then that adds all the groups

Similarly, with textmesh pro. If a package is imported with a TMP dependency, it would prompt to install the essentials then automatically reimport the package.

1 Like

Can anyone provide more detail on “Important: Marking package assets as Addressable requires Unity version 2020.2.0a9 or later.”

I am unsure on exactly why Unity 2020.2.0a9 is required to mark Assets in packages as Addressable? I am on Unity 2019.4.15f1 and the project uses several packages that includes assets. I am able to mark these assets as Addressable and add them to groups fine.

Is the issue relating to then importing this package into another project and then trying to build the Addressables?

@rkg_dcoleman It is related to a bug where scenes in a package can’t be loaded that was originally fixed in 2020.2.0a9. Looks like the fix was recently ported to 2019.4.10f1. Unity Issue Tracker - Scenes in an AssetBundles built from a package are not found by SceneManager

There is another bug where moving files to local packages would rename them to be lowercase. That was fixed in 2020.1.0a12 which enforces the use of Asset Pipeline v2. Unity Issue Tracker - Moving files in local packages causes them to be renamed to lowercase when using Asset Pipeline v1

So marking assets in packages as Addressable should work in 2019.4.10f1+ as long as Asset Pipeline v2 is used. We will look into updating this in the docs as well :slight_smile:

1 Like

@pillakirsten

However, as mentioned above, if the package is immutable, the schema assets cannot be changed.
Hi, is there any progress on that?
I’m having exactly this problem.:frowning:

I have a package in a private Git repository, and that package has asset groups.
As you said, the “Content Packing & Unloading” path shows a strange GUID and fails to load.

we won’t get this bug when clone the Git repo, install it as a local package, and change the “Content Packing & Unloading” path manually,
However, for ease of use, we want to install the package from Git.

I was able to resolve a similar issue by using ‘’ build and load paths in my source package’s addressable asset group settings. (I believe this process was described in an older version of the addressables documentation, but I could not find it anymore.)

Under the source package asset group’s ‘Content Packing & Loading’ settings:

  • Set “Build & Load Paths” to “”

  • Set “Build Path” to “”. This will reveal a text-entry field for the custom build path. Enter [UnityEngine.AddressableAssets.Addressables.BuildPath]/[UnityEditor.EditorUserBuildSettings.activeBuildTarget]

  • Set “Load Path” to “”. This will reveal a text-entry field for the custom load path. Enter {UnityEngine.AddressableAssets.Addressables.RuntimePath}/[UnityEditor.EditorUserBuildSettings.activeBuildTarget]

These instructions assume you are using Addressables version 1.19.17.

I think it would be nice if the addressables package made this process easier. It’s not obvious that you have to set up custom paths just to include an asset group in a package.

1 Like

@pillakirsten By the way, I noticed with a recent Addressables update (sometime after version 1.19.9), the Unity editor would sometimes replace an addressable group’s custom load and build paths with the default Local.BuildPath and Local.LoadPath settings. It does this without any indication that it’s being done, and I end up having to revert the change manually.

EDIT: It appears the custom paths are modified when entering Play mode.

1 Like

I use the paths on the packages and exactly the same thing you described is happening on my projects.

I would love to get some input from one of the Addressables developers regarding the use of Addressable Groups inside Unity Packages.

@pillakirsten

Edit: I just noticed @beevik has created another thread about that specific issue:
https://discussions.unity.com/t/868989

The addressables system is structured in a way that makes it almost impossible to work correctly with package-based addressable assets. A project using addressables requires an “AddressableAssetSettings” asset, which lists (a) the addressable group assets used by the project, and (b) the addressable profile paths used by the project. However, bundled asset group schema assets – which could be defined inside a package – contain GUID-based back-references to profile paths listed in the AddressableAssetSettings asset. This creates a problem, because a project’s AddressableAssetSettings asset is outside the scope of the package’s group schema asset.

Until recently, the work-around has been to use custom packing & loading paths for asset groups defined inside of packages. But this work-around has been broken by v1.19.11 of the addressables package.

So what now is the proper way to add addressable assets to packages?

1 Like

Is there any progress on this?

I was thinking of utilizing Unity Packages in a new project with multiple features managed by possibly different teams. I’m investigating if this is feasible using Addressables for asset management.

Hi all the custom paths bug is fixed in 1.19.19
“Fixed issue where BundledAssetGroupSchema custom paths reset to default local paths after a domain reload.”

The current way to add addressable assets from packages is to make a copy of the group asset and its schemas, and store it in the Assets folder. There is a sample tool called “Import Existing Group” that shows how to do this, and you can install it from the PackageManager > Addressables tab. It’s very barebones at the moment, and will be improved in the future.
https://docs.unity3d.com/Packages/com.unity.addressables@1.19/manual/ImportExistingGroup.html

1 Like