Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Question Addressables, AssetReference and Custom UPM Package

Discussion in 'Addressables' started by wesmag, Feb 8, 2022.

  1. wesmag

    wesmag

    Joined:
    Mar 25, 2020
    Posts:
    34
    Hello,

    Addressables Version 1.19.11
    Unity: 2020.3.12f1

    Question: How best to manage assets that reside within a custom UPM package?

    I am developing a couple of custom UPM packages. Inside these packages are assets, with Monobehaviours, that have AssetReference fields. These reference a variety of assets. In this case, the AssetReferences are attempting to reference assets inside the same package.

    The result is:

    upload_2022-2-8_10-43-47.png

    This make some sense, as the same material reference is inside a package and not under the Asset folder of the project.
    1. Is there a simple way around this that still allows references into the package?
    2. If not, what is the recommended way to handle this?
    I noticed that we can hook into a variety of UPM based events i.e:

    Code (CSharp):
    1. Events.registeringPackages
    2. Events.registeredPackages
    But these appear to be called only when packages are installed? I'd prefer, for testing purposes, another event where I can check these assets exist under Assets folder. If not, perform the setup. Is there a boot time package load/init event that I can hook into and perform a check there? If the check fails I would then:
    1. Create Addressables settings if needed
    2. Copy the Assets to the Assets folder
    3. Create the relevant group for these groups
    Are there currently any best practices around this? It appears TMP copies required assets to the project directory at install time. So I am assuming it is something like that.

    Thanks.
     
  2. wesmag

    wesmag

    Joined:
    Mar 25, 2020
    Posts:
    34
    Actually, I do appear to just be able to reference the assets in the package directly in an asset group, it appears. The path/key is of the form: "Packages/[PACKAGE_NAME]/Runtime/Assets/[PATH]/[AssetName].

    But still not sure if this is the recommended way.