I am trying to allow users to change the main character in their game by loading different addressable asset packages from different AWS S3 Folders and running into trouble.
In this example I am just taking the same little house image and building one package with the house colored red, and uploading it to AWS Location /redfolder . Then I am changing the color of the house image and uploading it to a different AWS Location / bluefolder . In both cases the “…unitybuiltinshaders…” file has the same file name.
I intend to set a {foldername.name} public static variable to control which folder to pull from in the future but for now I am just switching the profile manually in the inspector before runtime. Even after changing the profile manually, I can only ever load one version of the house (often it is the most recently built and uploaded one)
Here is a video example: AddressableAssetsRemoteLoadPathHelp
I would really appreciate any ideas you might have on how to solve for this.
What you’re doing is changing the profile? As far as I can tell ( I am still figuring things out myself) those profiles are there to hold build settings. I am not sure if they play a significant part in loading.
I have done what you are trying to do but using different bundles and catalogs. By manually loading catalogs and and loading assets from those. I think this is what you have to do.
take a look here:
https://docs.unity3d.com/Packages/com.unity.addressables@1.8/manual/AddressableAssetsGettingStarted.html#loading-content-catalogs
Thanks for reaching out, let me go over a few things.
First, your experiment (without using {})…
For play mode, if you are in “use asset database” mode, then it will use the latest data in the profile, but it will be loading all content from local asset database content, not from the server. So in this play mode you’d be seeing the house as whatever color it is in your project.
If you use “use existing build” then it will use the catalog to look up urls, and actually download bundles. The issue here would be that the catalog is built when you build addressables content, not when you enter play mode. Which means if you set it to blue, build your content (and thus your catalog), then change it to red, then play mode will load that catalog build around the blue data.
Second, your {} work…
To actually get this working in a regular runtime environment, you have two options.
- use TransformInternalId (TransformInternalId | Addressables | 1.16.19). If you set a callback on this, every time we evaluate a path, we’ll send it through this method. Here you could have some string parsing logic to deterimine if it’s your red/blue house and alter the path accordingly. In your case it could be as simple as a string replace of Replace(“red”,“blue”) or vice versa. Generally using TransformInternalId is just for cases where people need things continually dynamic as the app runs, but it’s also a bit easier to use than {}
- option two is to use {} in your path. using {foldername.name} in the load path, will get set to some path at runtime. The key here is that the {} get evaluated when the catalog is loaded (not when the asset is requested). So you need to be sure to set your foldername.name variable before addressables initializes.
With either version you choose, I recommend at least overriding TransformInternalId to do some Debug.Log() work to show what’s being loaded.
One additional option I’ll mention… you could build all this together if you have all the assets in-project. If there’s a red house and blue house in the unity project, you could give them both the same address, but different labels. Then use the MergeMode in LoadAssetsAsync to load either [“house”, “red”] or [“house”, “blue”]. Odds are, this would not be right for you, but mentioning it just in case.
1 Like