Bug - Resources.Load as Gameobject no longer working in IOS 8 / Xcode 6.3 / Unity 5.0.1

Hi,

I’ve tracked down what looks like a bug in Unity 5.0.1 when using Xcode 6.3 to build to an IOS 8.3 device. When using the following code to load a prefab as a game object, the resource loaded is null, which was not the case when deploying the same code to Android or in the Editor:

        GameObject obj=Resources.Load("UnitAbilityListPrefab", typeof(GameObject)) as GameObject;
        if(obj==null){
            Debug.Log("load unit ability fail, make sure the resource file exists");
            return;
        }
        UnitAbilityListPrefab prefab=obj.GetComponent<UnitAbilityListPrefab>();
        unitAbilityList=prefab.unitAbilityList;

If I change the code to not load as a Gameobject and instead load as the actual object type I want, then it works. For example, the following code does not result in a null resource load:

UnitAbilityListPrefab prefab2 = Resources.Load ("UnitAbilityListPrefab", typeof (UnitAbilityListPrefab)) as UnitAbilityListPrefab;
       
        if (prefab2 == null) {
            Debug.Log ("Raj Load Failed - Unit Ability still null");
            return;
        } else {
           
            Debug.Log ("Raj Load Succeeded for Unit Ability prefablist");
           
        }
       
        unitAbilityList = prefab2.unitAbilityList;

The above error appears in both Mono build and IL2CPP. It results in a null reference exception obviously and is currently preventing me from finishing my next project. Does anyone know if this bug has been identified or not? If not, I will submit a bug report.

Why don’t you use the generic overload of Resources.Load (e.g: Resources.Load)

I’m actually not familiar with that overload … can you give me an example of its usage?

Yes, It’s more common to use the generic versions of these methods (C# has support for generics since 2.0).

So, according to the information you provided, your code should be:

UnitAbilityListPrefab prefab2 = Resources.Load<UnitAbilityListPrefab>("UnitAbilityListPrefab");

Cool … thanks.

As I mentioned, though, it does seem like a bug because the first version of the code returns null just for IOS builds whereas for PC and Android and Editor, it does not. Furthermore, the second version of the code seems to work in IOS builds as well. Still, I do appreciate the chance to learn some new scripting … your version is much cleaner. :slight_smile:

Actually, I looked into it further and it seems that the way I code it doesn’t matter. At several scenes of the game, either method works to load the resource file. However, when I enter a specific scene (gameplay level), I get some error messages in Xcode and neither method seems to work in loading the prefab from Resources folder. This is the message I get in Xcode:

Could not open file /private/var/mobile/Containers/Bundle/Application/CFA1E2AB-E17E-4157-B8DF-95C592DC2302/DemonHuntersSagaDungeonHellDragon.app/Data/resources.assets for read
(Filename: Line: 54)

Has anyone else seen this as well? Anyone know what might be causing this and what, if any, workaround exists?