Resources.LoadAsync cannot be used in iOS

I want to load resources async when my game is running. So I decide to use Resources.LoadAsync.

Actually, It works well in Editor Mode. But when I get to build iOS, one error comes out.

  1. I tried to delete this sentence Resources.LoadAsync and it built well. Then I added this sentence and this error came out again.
  2. I tried to build Android from my PC, and it’s OK. I can also run it in Editor Mode. This error only occurs when building iOS.
  3. I tried to upgrade my Unity from 4.5.4 to 4.5.5, but this error is still there.

I find nobody who met the same problem before, so I have to get there and ask you guys.

I would appreciate any help. Thanks for your time.

my code is like this:

using UnityEngine;
using System.Collections;

public class ExampleClass : MonoBehaviour {
    void Start() {
        StartCoroutine(LoadTexture());
    }
    IEnumerator LoadTexture() {
        GameObject go = GameObject.CreatePrimitive(PrimitiveType.Cube);
        ResourceRequest request = Resources.LoadAsync<Texture2D>("glass");
        yield return request;
        go.renderer.material.mainTexture = request.asset;
    }
}

and when I build iOS, this error comes out:

Cross compilation job
Assembly-CSharp.dll failed.
UnityEngine.UnityException: Failed AOT
cross compiler:
/Applications/Unity/Unity.app/Contents/PlaybackEngines/iOSSupport/Tools/OSX/mono-xcompiler
–aot=full,asmonly,nodebug,static,outfile=“Assembly-CSharp.dll.s”
“Assembly-CSharp.dll” current dir :
/Users/xxxx/Desktop/ParkourX/Parkour/Temp/StagingArea/Data/Managed
Env: Apple_PubSub_Socket_Render =
‘/tmp/launch-CawMnu/Render’ LOGNAME =
‘xxxx’
__CHECKFIX1436934 = ‘1’ MONO_PATH = ‘/Users/xxxx/Desktop/ParkourX/Parkour/Temp/StagingArea/Data/Managed’
TMPDIR =
‘/var/folders/bn/ts33w4bs0sz9gtnyqwxf99_c0000gn/T/’
USER = ‘xxxx’ SSH_AUTH_SOCK =
‘/tmp/launch-iXaAd5/Listeners’
GC_DONT_GC = ‘yes please’ SHELL =
‘/bin/bash’
__CF_USER_TEXT_ENCODING = ‘0x1F5:0:0’ GAC_PATH =
‘/Users/xxxx/Desktop/ParkourX/Parkour/Temp/StagingArea/Data/Managed’
HOME = ‘/Users/xxxx’ PATH =
‘/usr/bin:/bin:/usr/sbin:/sbin’ result
file exists: False. Timed out: False
stdout: stderr:

at
UnityEditor.MonoProcessUtility.RunMonoProcess
(System.Diagnostics.Process process,
System.String name, System.String
resultingFile) [0x00000] in unknown>:0 at
UnityEditor.MonoCrossCompile.CrossCompileAOT
(BuildTarget target, System.String
crossCompilerAbsolutePath,
System.String
assembliesAbsoluteDirectory,
CrossCompileOptions
crossCompileOptions, System.String
input, System.String output,
System.String additionalOptions)
[0x00000] in :0 at
UnityEditor.MonoCrossCompile+JobCompileAOT.ThreadPoolCallback
(System.Object threadContext)
[0x00000] in :0
UnityEditor.HostView:OnGUI() Click to
expand…

Error building Player: UnityException: Cross compilation failed.

If I delete this two sentences, like this below, it works through building iOS:

using UnityEngine;
using System.Collections;

public class ExampleClass : MonoBehaviour {
    void Start() {
        StartCoroutine(LoadTexture());
    }
    IEnumerator LoadTexture() {
        GameObject go = GameObject.CreatePrimitive(PrimitiveType.Cube);
        /*ResourceRequest request = Resources.LoadAsync<Texture2D>("glass");
        yield return request;*/
        yield return null;
        //go.renderer.material.mainTexture = request.asset;
    }
}

Hi, today I had the same problem and I have figured out that if I use non-generic version of the method LoadAsync, i.e. call Resources.LoadAsync(“glass”), this fixes the problem and doesn’t produce the cross-compilation error. Also note, that most probably you have stripping level set in your build settings, because I have this error only when stripping is something different from “Disabled”.