Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by Dave Hawes · Jun 30, 2010 at 04:21 PM · texturematerialeditor-scriptingassetbundle

Missing textures & materials in asset bundle

I am creating an asset bundle which contains a variety of materials, textures, gameobjects, meshfilters and meshrenderers. I am doing so using an editor script which is run from a command line. When I loop over and check the materials on the main asset before creating the bundle everything looks fine.

logFile.WriteLine("@@@@ BEGIN MAIN SCENE CHECK @@@@"); GameObject mainGO = sceneDummy.m_obj as GameObject;

         MeshRenderer[] meshRenderArray = mainGO.GetComponentsInChildren<MeshRenderer>(true);
         foreach (MeshRenderer mr in meshRenderArray)
         {
             logFile.WriteLine("Found MeshRenderer " + mr.name);
             foreach (Material m in mr.materials)
             {
                 if (m.shader == null)
                 {
                     logFile.WriteLine("Error diffuse shader missing from mat " + m.name);
                 }
                 else if (m.GetTexture("_MainTex") == null)
                 {
                     logFile.WriteLine("Error diffuse material missing from mat " + m.name);
                 }
                 else
                 {
                     logFile.WriteLine("Found material " + m.name);
                 }
             }
         }
         logFile.WriteLine("@@@@ END MAIN SCENE CHECK @@@@");            

         UnityEngine.Object[] allAssets = (UnityEngine.Object[])assetList.ToArray(typeof(UnityEngine.Object));
         BuildPipeline.BuildAssetBundle(sceneDummy.m_obj, allAssets, bundleTarget, BuildAssetBundleOptions.CompleteAssets | BuildAssetBundleOptions.CollectDependencies);

The log for this seems to indicate everything is fine. However when I load the main asset back in in my unity application using the following code.

void CreateModel(AssetBundle bundle) { bundle.LoadAll(); GameObject model = (GameObject)Instantiate(bundle.mainAsset); GameObject mainAssetGO = bundle.mainAsset as GameObject; m_models.Add(model);

 Debug.Log("CreatingModel");

 MeshRenderer[] meshRenderArray = mainAssetGO.GetComponentsInChildren<MeshRenderer>(true);
 foreach (MeshRenderer mr in meshRenderArray)
 {
     Debug.Log("Found MeshRenderer " + mr.name);
     foreach (Material m in mr.materials)
     {
         Debug.Log("Found material " + m.name);
         Texture2D tex = m.GetTexture("_MainTex") as Texture2D;

         if (tex != null)
         {
             Debug.Log("Found texture " + tex.name);
         }
         else
         {
             Debug.Log("Missing diffuse texture");
         }
     }
 }

 gameObject.GetComponent<MouseOrbit>().target = model.transform;

}

Whether I look at the instantiated object or not all the materials & textures appear to be missing. I have tried directly adding the textures and materials to the assetList but this had no effect.

What am I missing that is stopping the textures from being exported correctly?

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
1

Answer by Ricardo Arango · Jul 02, 2010 at 11:27 AM

I can build and load with no problems using this:

Create the bundle:

BuildAssetBundleOptions options = BuildAssetBundleOptions.CollectDependencies | BuildAssetBundleOptions.CompleteAssets;
BuildPipeline.BuildAssetBundle(AssetDatabase.LoadMainAssetAtPath("Assets/testAsset.prefab"), null, "Assets/testAssetBundle.unity3d", options);

Instantiate in another project:

WWW www = new  WWW (pathToBundle);
yield return www;
Instantiate(www.assetBundle.mainAsset);

Your code is almost correct, but you have to change

foreach (Material m in mr.materials)

to

foreach (Material m in mr.sharedMaterials)

As it will throw an error in Unity and disconnect the materials from the mesh, preventing a correct build.

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image user-3443 (google) · Jul 06, 2010 at 02:50 PM 0
Share

$$anonymous$$aking these changes reduced caused a number of material linkages to survive. Using an updated asset from the artist resolved the remainder though I am not sure why.

One thing still puzzles me, why the thrown error is not caught either by my script (which is wrapped in a try/except and logs the error) or by the command line output.

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

No one has followed this question yet.

Related Questions

How to extract every material from a scene inside an editor script? 0 Answers

AssetBundle to prefab => meshes/textures missing 1 Answer

Replace texture without touching materials? 1 Answer

Editor Scripting 1 Answer

dynamic images for textures ar runtime 2 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges