Addressables work when running in Editor, but not on iOS build

Hi, I am having an issue with Addressables, and I don’t know quite enough about this system to know what is going on. I setup addressables to load at the start of my scene, and when running in Unity Editor, it works as it should. However, when I build it to Xcode and run it on my iPhone, it doesn’t work, and it provides this set of errors in the Xcode log (Note: this is not the full log. If you need that to troubleshoot, let me know and I will get you the whole thing):

Uploading Crash Report
MissingMethodException: Default constructor not found for type UnityEngine.ResourceManagement.AsyncOperations.ProviderOperation`1[[UnityEngine.AddressableAssets.Initialization.ResourceManagerRuntimeData, Unity.Addressables, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null]]
  at System.RuntimeType.CreateInstanceMono (System.Boolean nonPublic) [0x00000] in <00000000000000000000000000000000>:0
  at System.Activator.CreateInstance (System.Type type, System.Boolean nonPublic) [0x00000] in <00000000000000000000000000000000>:0
  at UnityEngine.ResourceManagement.Util.LRUCacheAllocationStrategy.New (System.Type type, System.Int32 typeHash) [0x00000] in <00000000000000000000000000000000>:0
  at UnityEngine.ResourceManagement.ResourceManager.CreateOperation[T] (System.Type actualType, System.Int32 typeHash, System.Int32 operationHash, System.Action`1[T] onDestroyAction) [0x00000] in <00000000000000000000000000000000>:0
  at UnityEngine.ResourceManagement.ResourceManager.ProvideResource (UnityEngine.ResourceManagement.ResourceLocations.IResourceLocation location, System.Type desiredType) [0x00000] in <00000000000000000000000000000000>:0
  at UnityEngine.ResourceManagement.ResourceManager.ProvideResource[TObject] (UnityEngine.ResourceManagement.ResourceLocations.IResourceLocation location) [0x00000] in <00000000000000000000000000000000>:0
  at UnityEngine.AddressableAssets.Initialization.InitializationOperation.CreateInitializationOperation (UnityEngine.AddressableAssets.AddressablesImpl aa, System.String playerSettingsLocation, System.String providerSuffix) [0x00000] in <00000000000000000000000000000000>:0
  at UnityEngine.AddressableAssets.AddressablesImpl.InitializeAsync (System.String runtimeDataPath, System.String providerSuffix) [0x00000] in <00000000000000000000000000000000>:0
  at UnityEngine.AddressableAssets.AddressablesImpl.InitializeAsync () [0x00000] in <00000000000000000000000000000000>:0
  at UnityEngine.AddressableAssets.AddressablesImpl.get_InitializationOperation () [0x00000] in <00000000000000000000000000000000>:0
  at UnityEngine.AddressableAssets.AddressablesImpl.LoadAssetAsync[TObject] (System.Object key) [0x00000] in <00000000000000000000000000000000>:0
  at LoadTexture.OnEnable () [0x00000] in <00000000000000000000000000000000>:0
(Filename: currently not available on il2cpp Line: -1)

Unloading 8 unused Assets to reduce memory usage. Loaded Objects now: 12309.
Total: 15.436083 ms (FindLiveObjects: 0.949833 ms CreateObjectMapping: 0.146542 ms MarkObjects: 14.286542 ms  DeleteObjects: 0.052500 ms)

And here is my code that runs my addressable system:

public string backgroundTextureAddress;
    [HideInInspector]
    public Camera[] allCams;
    private Nav[] navsInNode;
    private Camera[] cameras;
    private Camera[] newCameras;
    private bool keepThisLoaded;

    private void OnEnable()
    {
        if (transform.parent.Find("Background").GetComponent<SpriteRenderer>().sprite == null)
        {
            Addressables.LoadAssetAsync<Sprite>(backgroundTextureAddress).Completed += OnThisBGDLoadComplete;
        }
    }

    private void OnDisable()
    {
        transform.parent.Find("Background").GetComponent<SpriteRenderer>().sprite = null;
        Resources.UnloadUnusedAssets(); // I have this here so that it will save on memory. Let me know if there is a better way to do this
    }

    private void OnThisBGDLoadComplete(AsyncOperationHandle<Sprite> async)
    {
        transform.parent.Find("Background").GetComponent<SpriteRenderer>().sprite = async.Result;
    }

What does this mean? Am I doing something wrong? Any help would be greatly appreciated!

Charlie

I think I may have fixed my issue. Found this thread: Addressables and Code Stripping (IL2CPP) and in it, they said that the addressables needed to be built before they can be used (which I then found in the documentation. They could have made it bold or something). Went to Addressables>Build>Build Player Content (apparently you can also call AddressableAssetSettings.BuildPlayerContent(), though I am curious how it affects load time), and it is now working on my phone. Still need to do some testing to ensure it is working fully, but this seems to have been my issue.

1 Like

Yay, calling Build->Build Player Content throws an exception that appears to be an internal unity error -.-