Search Unity

List/Array code that works on Editor not working on iOS? Help!?

Discussion in 'iOS and tvOS' started by SuperTalesNat, Aug 15, 2013.

  1. SuperTalesNat

    SuperTalesNat

    Joined:
    Mar 20, 2013
    Posts:
    18
    I'm seeing some issues that are completely perplexing me at this moment in my iOS build vs. Editor functionality.

    I have tried 2 methods now, and both are coming up short for me.

    I'm trying to take a number of Textures from an Asset bundle and assign them to an array on a GameObject in my scene. In the editor, it works flawlessly, in iOS the Textures are there, but nothing is being assigned (null).

    I have 'partially' tracked it down to System.Collections.Generic being used, and its not fully supported on iOS. That explains the issue with LISTs, .add, .clear, etc. but not with array's (i've now tried both).

    Some help would be greatly appreciated as i've burnt so many hours/days on this now trying to troubleshoot it. I would prefer Method #2, and both actually work in Editor, but both return null values between script #1 and #2 in either solution on iOS.

    METHOD #1 (using arrays to get/set the data):

    Code (csharp):
    1.  
    2.  
    3. //Script01 - The Initializer
    4.  
    5. using UnityEngine;
    6. using System.Collections;
    7.  
    8. public class AtlasLoader : MonoBehaviour {
    9.  
    10.     public string[] loadLandscapeName;
    11.     public GameObject loadScreenObj;
    12.  
    13.     IEnumerator Start()
    14.     {
    15.         isDownloading = true;
    16.  
    17.         //commence download of bundle.
    18.         d = WWW.LoadFromCacheOrDownload (atlasBundlePath_ios, 1);      
    19.         yield return d;
    20.         isDownloading = false;
    21.        
    22.         //any error messages are here.
    23.         if(d.error!=null) Debug.Log(d.error);
    24.  
    25.         loadSceneManager loadS = loadScreenObj.GetComponent<loadSceneManager>();
    26.  
    27.         //re-initialize the array to zero at load
    28.         System.Array.Resize(ref loadS.landscapePics,0);
    29.  
    30.         foreach(string pn in loadPortraitName){
    31.             d.assetBundle.Load(pn);
    32.             Texture2D loadPInstance = Instantiate(d.assetBundle.Load(pn)) as Texture2D;
    33.             loadPInstance.name = pn;
    34.             System.Array.Resize(ref loadS.portraitPics,loadS.portraitPics.Length+1);
    35.             loadS.portraitPics[loadS.portraitPics.Length-1] = loadPInstance;
    36.         }
    37.  
    38.         d.assetBundle.Unload(false);
    39.     }
    40. }
    41.  
    42.  
    43.  
    44. //Script02 - The Receiver Gameobject
    45.  
    46. using UnityEngine;
    47. using System.Collections;
    48.  
    49. public class loadSceneManager : MonoBehaviour {
    50.  
    51.     public GameObject[] pictures; //The gameobjects in scene that will have pics assigned to them
    52.     public Texture2D[] portraitPics; //the list of Textures to assign
    53.     public float pictureAtimer = 3.0f; //the timer to switch to the next picture
    54.  
    55.     void Start ()
    56.     {
    57.         StartCoroutine(PortraitLoad());
    58.     }
    59.  
    60.     IEnumerator PortraitLoad()
    61.     {
    62.         while (true) {
    63.             var newPicA = Random.Range(0,portraitPics.Length);
    64.                                
    65.             var pictureA = portraitPics[newPicA] as Texture2D;
    66.            
    67.             pictures[0].GetComponent<UITexture>().mainTexture = pictureA;
    68.            
    69.             yield return new WaitForSeconds(pictureAtimer);
    70.         }
    71.     }
    72. }
    73.  

    METHOD #2 (using LIST to get/set the data):

    Code (csharp):
    1.  
    2.  
    3. //Script01 - The Initializer
    4.  
    5. using UnityEngine;
    6. using System.Collections;
    7. using System.Collections.Generic;
    8.  
    9. public class AtlasLoader : MonoBehaviour {
    10.  
    11.     public string[] loadLandscapeName;
    12.     public GameObject loadScreenObj;
    13.  
    14.     IEnumerator Start()
    15.     {
    16.         isDownloading = true;
    17.  
    18.         //commence download of bundle.
    19.         d = WWW.LoadFromCacheOrDownload (atlasBundlePath_ios, 1);      
    20.         yield return d;
    21.         isDownloading = false;
    22.        
    23.         //any error messages are here.
    24.         if(d.error!=null) Debug.Log(d.error);
    25.  
    26.         loadSceneManager loadS = loadScreenObj.GetComponent<loadSceneManager>();
    27.  
    28.         //re-initialize the array to zero at load
    29.         loadS.landscapePics.Clear();
    30.  
    31.         foreach(string pn in loadPortraitName){
    32.             d.assetBundle.Load(pn);
    33.             Texture2D loadPInstance = Instantiate(d.assetBundle.Load(pn)) as Texture2D;
    34.             loadPInstance.name = pn;
    35.             loadS.portraitPics.Add(loadPInstance);
    36.         }
    37.  
    38.         d.assetBundle.Unload(false);
    39.     }
    40. }
    41.  
    42.  
    43.  
    44. //Script02 - The Receiver Gameobject
    45.  
    46. using UnityEngine;
    47. using System.Collections;
    48.  
    49. public class loadSceneManager : MonoBehaviour {
    50.  
    51.     public GameObject[] pictures; //The gameobjects in scene that will have pics assigned to them
    52.     public List<Texture2D> portraitPics = new List<Texture2D>(); //the list of Textures to assign
    53.     public float pictureAtimer = 3.0f; //the timer to switch to the next picture
    54.  
    55.     void Start ()
    56.     {
    57.         StartCoroutine(PortraitLoad());
    58.     }
    59.  
    60.     IEnumerator PortraitLoad()
    61.     {
    62.         while (true) {
    63.             var newPicA = Random.Range(0,portraitPics.Count);
    64.                    
    65.             var pictureA = portraitPics[newPicA];
    66.            
    67.             pictures[0].GetComponent<UITexture>().mainTexture = pictureA;
    68.            
    69.             yield return new WaitForSeconds(pictureAtimer);
    70.         }
    71.     }
    72. }
    73.