Hello everyone!
I’m new to Addressables. I implemented a system where it loads an Addressable Material and changes the material component of a renderer.
Basically:
[SerializeField] private AssetReference m_AssetReference;
void Start()
{
m_AssetReference.LoadAssetAsync<Material>().Completed += (async) =>
{
GetComponent<Renderer>().material = async.Result;
}
}
My structure is a little more complex than that since I’m using generics and 2 classes: 1 to just load and 1 to change the component and other things. But roughly it’s doing the same thing as the code above
For some reasons I can’t change sharedMaterial instead of the material on my project. But I have like 100 renderers on my scene that I should change their material. They load up and use 3 materials. So, for example, 40 objects load materialA and change, 40 objets load materialB and change and 20 objects load materialC and change.
On my game’s splash screen it downloads all necessary objects from Unity’s Cloud Content Delivery using Addressables.DownloadDependenciesAsync(label) so when it runs the code above, everything is already local.
When I run on iOS (iPhone XR) works perfectly fine. When I run on Android (Moto G Play 7) it crashes when it is loading/changing materials, I don’t know which of them for sure (crashing on loading or changing). I haven’t tested on other Android devices by now.
My question is: when I call LoadAssetAsync does unity really loads everytime or does it caches the asset? I might have a problem where I’m calling LoadAssetAsync 100 times when I really need was 3.
Thanks in advance!