It’s my first time using Addressables and I imagine my issue is a simple oversight on my part but I am unable to figure out what an error is trying to tell me when loading an addressable asset. I followed steps to configure a google cloud bucket to host the assets, and I believe I have set the addressable groups and assets settings correctly.
I can run the game in the editor with “Simulate Groups” play script, however upon building the game it can’t load the asset and throws:
Exception encountered in operation UnityEngine.ResourceManagement.ResourceManager+CompletedOperation`1[UnityEngine.Sprite], result='', status='Failed': Exception of type 'UnityEngine.AddressableAssets.InvalidKeyException' was thrown., Key=Assets/Resources_moved/Game Specific Assets/Interval Game/Photo/Heavy Guitar.png, Type=UnityEngine.Sprite
Is the key for the Addressable the name next to the checked addressable box in the inspector? (attached screenshot) Because it looks like they match.
Any assistance would be greatly appreciated,
Thanks!
You’re pretty much spot on, it just sounds like the key isn’t matched up.
Fiddling with keys directly can be a bit annoying. If you know the exact asset you want to target, like this texture, the easiest road is to use an AssetReference in your script. Something like this:
public AssetReference assRef;
public Material material;
IEnumerator Start()
{
if (!assRef.RuntimeKeyIsValid()) yield break;
yield return assRef.LoadAssetAsync<Texture2D>();
material.SetTexture(name: "_MainTex",
value: assRef.Asset as Texture2D);
}
Fiddling around with keys can be a bit painful if its not necessary.
Thanks for the reply! Maybe I must be misunderstanding keys for Addressables.
My goal is to download a random Image and AudioClip Addressable Asset from my google cloud server and load it into the game. I have selected to pack my assets seperately so I may download each asset individually, and I want to select the item to load by name. This code works in the editor however does not work in builds.
Oh interesting. In that case, what you’re doing should be able to work. I think you can pass in the asset name itself from the left-most column in the Asset Groups window rather than deal with the whole asset path. You can change that name to anything you want, even duplicates, so you could name them something like Photo1, Photo2, Photo3, Instrument1, Instrument2, etc and skip the path/file extension stuff altogether.
Another way would be to use asset labels, fetch all assets with the label Photo or Instrument, and then use a random int between 0 and the length of the IResourceLocation list count to pick one to load/use.
I was using the default name for the Addressable, which by default is the path, since I did not want to rename all my assets and I was previously loading these assets in with Resources.Load so the code was easy to transfer.
In my initial post with the error message and the screenshot of the Addressable name, it seems that the keys shoud match. So I am starting to think that the issue is not about the naming, rather an issue with building the bundles and hosting them on a Google Cloud Bucket or some other Addressable setting. I’ve attached screenshots of my settings.
Hm, the only other thing I can think of is that RemoteLoadPath has [BuildTarget] at the end in the Profiles window but no platform name is appearing there in the first screen shot. Are the bundles being kept in a /Android or /iOS directory?
When I build the Asset Content it creates the platform directory, in my case the WebGL folder, and that’s what I have uploaded to the server. If I’m not mistaken, [Build Target] is this directory and the one you’re asking if it’s actually there.
Yeah sorry, that’s correct. Just guessing really, I’m out of ideas. I’ve read that WebGL has some caching and support problems when it comes to Addressables so that might be the problem.
But back to your problem. It is possible that the game cannot access the catalog, or something similar to that. You may want to do something far simpler, just so see if it works with your storage. Maybe even create a new test project and get your storage working etc…
Add just one file and change this long key from ““Assets/Resources_moved/Game Specific Assets/Interval Game/Photo/” + selectedInstrument+”.png"
to
“testImage” and do the other things like building etc…
Then call Addressables.LoadAssetAsync(“testImage”) see if it works. And it should. After this, you want to set the play script to “Use Existing Build” (not simulate) and try loading again. If this works, then try using your cloud storage and test again.