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 When remote, what is the address string of an addressable asset?

Discussion in 'Addressables' started by SgtLame, Apr 15, 2023.

  1. SgtLame

    SgtLame

    Joined:
    Nov 26, 2015
    Posts:
    129
    Hi,
    I'm trying to learn how to use addressables and I studied several tutorials and docs. All of these pass very quickly on getting an asset with its string address and the Addressables.LoadAssetAsync(string) method, and then focus exclusively on AssetReference.
    But if I'm not wrong, using AssetReference means that the asset, even if you uploaded it on a remote server, whether its custom or CDN, is still in your Unity project, on your hard drive, which looks kind of tightly coupling the assetdatabase, though remote through the addressable system, and the build that will consume it.
    what I mean is, what if I have two Unity projects, one used for modeling, creating and uploading assets as addressables on remote locations, and the other Unity project being kind of a lightweight client that will consume those addressable assets? One way or another, the latter will have to download assets using their remote address. So let's say I have a Unity project where I create assets and upload them to a custom Remote.LoadPath set as "https://www.mydomain.com/addressables/[BuildTarget]", and an asset that what set addressable and having the default address: "Assets/myModel.prefab".
    What I want to do is fetching this asset from the "lighweight client" Unity projet, using something like that:
    Addressables.LoadAssetAsync<GameObject>("https://www.mydomain.com/addressables/Assets/myModel.prefab");
    .
    Of course, there is something I don't get and it doesn't work, throwing an "UnityEngine.AddressableAssets.InvalidKeyException" exception.
    What is it that I do not understand?
     
    jwzhang19_unity likes this.
  2. Gordon_G

    Gordon_G

    Joined:
    Jun 4, 2013
    Posts:
    358
    It depends

    I'm not sure what you mean using AssetReference in the context of your question - whether or not content is included in the app build vs content that is not included and will be downloaded from a remote source (a server).

    It is my understanding the Load Path in the group settings determines whether the content is included in the app or is not and expected to be remote. Choose the Local or Remote path options.

    I might be wrong, but the AssetRefernce resolves to the correct location for the loader call when you identify it in the needed parameter of the call - you supply the asset group label or what ever, and it returns a reference to the asset that you can use when loading returns success.
     
    Last edited: Apr 16, 2023
  3. DeathPro

    DeathPro

    Joined:
    Jul 28, 2018
    Posts:
    69
    When you set an Addressable Group to "Remote", those assets will not be included in the build. You need to download your Remote Addressable Assets before loading them.

    As far as I remember, you can directly call LoadAsset callback for remote assets. It will try to download the actual asset and cache it for further use.

    Addressables.LoadAssetAsync<GameObject>("Assets/myModel.prefab");

    Also, you can change the addressable assets' address which is one of their keys. Keep them simple. You don't have to write your domain name and addressable asset address. Just write directly your Addressable Asset Key.

    And you want some kind of multiple project setup with addressable. I could manage to work with Multiple Project Setups with Addressables. It works but you need to test it lots of times. But what I can say is the documentation has so less information and (most importantly) there are not any examples to get it done. You can find more information about Multiple Project Setups here
     
  4. Gordon_G

    Gordon_G

    Joined:
    Jun 4, 2013
    Posts:
    358
    Where do you set that? The only way I see to make a group "Remote" or "Local" is to set the Build and Load Paths to local or remote in the group's Inspector.
     
  5. DeathPro

    DeathPro

    Joined:
    Jul 28, 2018
    Posts:
    69
    Those "Remote" and "Local" values coming from Addressable Assets Profiles
     
  6. Gordon_G

    Gordon_G

    Joined:
    Jun 4, 2013
    Posts:
    358
    Understood, but I thought you were saying that there is another way to mark a group as local or remote - like a checkbox somewhere that you flip on or off. Perhaps I misunderstood and you are simply confirming those paths are the only way set the remote vs local status?
     
  7. DeathPro

    DeathPro

    Joined:
    Jul 28, 2018
    Posts:
    69
    "Remote" and "Local" things are just default variables from the default addressable asset profile. You can set paths for these variables and when you change an Addressable Group to "Remote" or "Local", you don't have to write the corresponding path for it. It is already written in Addressable Asset Profile. You can also set "Custom". With Custom you can change it differently from others like "Remote" or "Local" by default.
     
  8. SgtLame

    SgtLame

    Joined:
    Nov 26, 2015
    Posts:
    129
    Thanks guys! I'll try those leads.
     
    DeathPro likes this.
  9. jwzhang19_unity

    jwzhang19_unity

    Joined:
    Jan 31, 2023
    Posts:
    1
    I seem to run into the same situation, trying to set up a UGC asset uploader and a game client to pull those content.

    Got the same InvalidKeyException, and trying to figure out if it's possible to fix it within the Addressable framework or maybe go back to direct Web request.