- Home /
Loading prefab from Server as AssetBundle, NO material/texture loading (PINK result)
My question is, I am trying to load an AssetBundle of a prefab I created, from my server. In the server I have the next folder distribution:
public_http/Assets/ 
 AssetBundles(Here I have all my AssetBundles prefab, material, textures) 
 cube_example (Here I have my real prefab, texture, material and gameobject)
I am using the next code to create my AssetBundles:
 using UnityEditor;
 public class CreateAssetBundles
 {
      [MenuItem("Assets/Build AssetBundles")]
      static void BuildAllAssetBundles()
      {
          BuildPipeline.BuildAssetBundles("Assets/AssetBundles");
     }
 }
And I am using this script to load my Assets:
 using System;
 using UnityEngine;
 using System.Collections;
 public class CachingLoadExample : MonoBehaviour
 {
     public string BundleURL; // --> http://Myserver/public_http/Assets/AssetBundles/cube_prefab (path to the AssetBundle)
     public string AssetName; // --> Cube_pref (name of the Asset prefab)
     public int version;
     void Start()
     {
         StartCoroutine(DownloadAndCache());
     }
     IEnumerator DownloadAndCache()
     {
     // Load the AssetBundle file from Cache if it exists with the same version or download and store it in the cache
         using (WWW www = WWW.LoadFromCacheOrDownload(BundleURL, version))
         {
             yield return www;
             if (www.error != null)
                 throw new Exception("WWW download had an error:" + www.error);
             AssetBundle bundle = www.assetBundle;
             if (AssetName == "")
                 Instantiate(bundle.mainAsset);
             else
             {
                 GameObject gameObject = bundle.LoadAsset(AssetName) as GameObject;
                Instantiate(bundle.LoadAsset(AssetName));
            }
             // Unload the AssetBundles compressed contents to conserve memory
             bundle.Unload(false);
         } // memory is freed from the web stream (www.Dispose() gets called implicitly)
     }
 }
The result is I obtain my prefab without any material/texture (PINK colored cube) allthough in the AssetBundle manifests I can see it has linked the dependecies. I really don't know what's happening. I don't know if I am construction the AssetBundle in a mistaken way or if I am trying to load the prefab in the wrong way.
Any help would be perfect.
I really don't know. How would you include them in the bundle?
Answer by Elcolmo · May 13, 2016 at 11:13 AM
I have solved my problem. My error was to create AssetBundles of each prefab, material and texture. Know I have created a unique AssetBundle of the hole folder and I am calling the prefab. The result is the prefab with a texture on it.
Thank you for your reply. I have a question: How to create a unique AssetBundle of the hole folder. Thank you so much !
Your answer
 
 
             Follow this Question
Related Questions
A texture/material loading problem in Unity 4 iPhone 0 Answers
Is there an option to pack textures using AssetBundles using Unity's image compression? 1 Answer
Use assets from another project? 1 Answer
Prefab material 1 Answer
Texture on instantiated asset bundle sometimes black only on iPhone 0 Answers
 koobas.hobune.stream
koobas.hobune.stream 
                       
                
                       
			     
			 
                