Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.

IOS stripping and Instantiate

Discussion in 'iOS and tvOS' started by tigershan, May 4, 2011.

  1. tigershan

    tigershan

    Joined:
    Jul 29, 2010
    Posts:
    73
    I am calling Object.Instantiate on iphone with www load asset bundle.

    When I call stripping, it doesn't load the file with some missing ID error.

    So I included the model and texture, and the problem is gone... However I include another model and texture it doesn't work anymore, so Do I have to have the exact same model to be able to instantiate the object?

    That would have no use on loading assets in runtime if I had to store the exact model in project anyways....

    Thanks ahead.
     
  2. andeeeee

    andeeeee

    Joined:
    Jul 19, 2005
    Posts:
    8,768
    Can you post the code you are using to load the bundle and instantiate the assets? Are you saying that this only happens when you use stripping?
     
  3. tigershan

    tigershan

    Joined:
    Jul 29, 2010
    Posts:
    73
    I saw somewhere else it has the same problem, this is the problem I got from xcode:


    Could not produce class with ID 33


    Could not produce class with ID 23




    Code (csharp):
    1.     public IEnumerator WaitLoading(WWW download) {
    2.         yield return download;      
    3.     }
    4.  
    5.  
    6.     private void GenerateModel() {
    7.                
    8.             assetBundle = download.assetBundle;
    9.            
    10.             // Alternatively you can also load an asset by name (assetBundle.Load("my asset name"))
    11.             GameObject go= (GameObject)assetBundle.mainAsset;
    12.            
    13.             if (go != null)
    14.                 instanced = (GameObject)UnityEngine.Object.Instantiate(go);
    15.             else
    16.                 Debug.Log("Couldnt load resource");
    17.        
    18.        
    19.     }
    20.    
    21.     private void StartDownload () {
    22.    
    23.         download = new WWW ("http://mydownloads/AssetBundles/" + url);
    24.    
    25.        
    26.        
    27.         StartCoroutine(WaitLoading(download));
    28.    
    29.  
    30.  
    31.     }
    32.    
    33.    
    34.     void Update()
    35.     {
    36.         if(download != null)
    37.         {
    38.             if(download.isDone  !Generated)
    39.             {
    40.                 GenerateModel();
    41.                 Generated = true;
    42.             }
    43.         }  
    44.            
    45.        
    46.        
    47.        
    48.     }
    49.    
    50.    
    51.  
    52.  
    53.     void OnGUI()
    54.     {
    55.         GUILayout.Space(guiOffset);
    56.         GUILayout.BeginHorizontal();
    57.         if (download == null)
    58.         {
    59.        
    60.             if (GUILayout.Button("Download " + url))
    61.                 StartDownload();   
    62.         }
    63.         else
    64.         {
    65.             if (download.error == null)
    66.             {
    67.                 int progress =(int)(download.progress * 100);
    68.                 GUILayout.Label(progress + "%");   
    69.                
    70.                
    71.                
    72.            
    73.                 if (download.isDone  GUILayout.Button("Unload Resource")    )
    74.                 {
    75.                     // Destroy the instantiated object
    76.                     Destroy(instanced);
    77.                     // Dispose the WWW class
    78.                     // (This happens automatically from the GC, but you can do it explicitly to make sure it happens early on)
    79.                     download.Dispose();
    80.                     download = null;
    81.                    
    82.                     Generated = false;
    83.  
    84.                     // Unload the whole asset bundles and any loaded assets
    85.                     assetBundle.Unload (true);
    86.                     assetBundle = null;
    87.                 }
    88.                
    89.                
    90.             }
    91.             else
    92.             {
    93.                 GUILayout.Label(download.error);       
    94.             }  
    95.         }
    96.         GUILayout.EndHorizontal();
    97.     }
     
  4. liudibo

    liudibo

    Joined:
    Dec 9, 2010
    Posts:
    75
  5. tigershan

    tigershan

    Joined:
    Jul 29, 2010
    Posts:
    73
    Selected dependencies had Prefab, Material, MeshFilter, MeshRenderer, Animation and Texture2D, I declared all these variables...

    Now it actually doesn't crash at 0%, it loads the file to 100%, but after that, it gives me an error:
    "Could not produce class with ID 43", what's that component anybody know?
     
  6. tigershan

    tigershan

    Joined:
    Jul 29, 2010
    Posts:
    73
    Got it fixed, rather than include MeshFilter and MeshRenderer, Just declared Mesh as a dummy variable, and the problem went away.
     
  7. yltang

    yltang

    Joined:
    Nov 20, 2010
    Posts:
    28
    im freshman,
    and confused that
    How to declared Mesh as a dummy variable?
    Can anyone give me some details?
     
  8. Dreamora

    Dreamora

    Joined:
    Apr 5, 2008
    Posts:
    26,601
    put at the top:

    private Mesh meshDummy; ;)
     
  9. yltang

    yltang

    Joined:
    Nov 20, 2010
    Posts:
    28
    I still could not make it work,
    I put this declaration at the top of a script atatched to a prefab in the bundle assets package made by "BuildPipeline.BuildAssetBundle".

    but still failed with "Could not produce class with ID 137" when "Instantiate(www.assetBundle.mainAsset);" is called.
     
  10. Dreamora

    Dreamora

    Joined:
    Apr 5, 2008
    Posts:
    26,601
    Did you rebuild the player?

    asset bundles don't contain any code at all, its all in the application. asset bundles only have the "hints" on which script is attached
     
  11. yltang

    yltang

    Joined:
    Nov 20, 2010
    Posts:
    28
    find the problem,
    I made a mistake, I declared the dummy variable using public.

    I changed to private,and it works :razz:



    but.......
    when i pack a prefab with animation in the modal, it failed again.
    so......
     
    Last edited: Jun 24, 2011
  12. Dreamora

    Dreamora

    Joined:
    Apr 5, 2008
    Posts:
    26,601
  13. yltang

    yltang

    Joined:
    Nov 20, 2010
    Posts:
    28
    It seems additional variable of SkinedMeshRenderer is need for model with animation.
    I add it and it seems work fine.

    and the link.xml seems work fine too.
    for I not need to change the package by this way, I 'd select this way. :)
     
unityunity