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 hvilela · Jul 25, 2013 at 08:03 PM · iosassetbundlecustom shader

iOS, Assentbundles and Custom Shaders

There's something special about shaders in assent bundles in iOS? When I do the process below and use Windows as target, everything run smoothly. When it do it in iOS, the materials contained in the asset bundle are all OK except that ones that uses custom shaders. Am I doing something wrong?

PS: The asset bundle do contains the custom shaders (Im using BuildAssetBundleOptions.CollectDependencies) and this process do works in windows bundles.

 PushAssetDependencies

     BuildAssetBundle // Materials and Shaders
 
     PushAssetDependencies
         BuildPlayer
     PopAssetDependencies
 
 PopAssetDependencies
Comment
Add comment · Show 2
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 equalsequals · Jul 25, 2013 at 09:48 PM 0
Share

Is the problem only in Editor or on an iOS device?

avatar image hvilela · Jul 25, 2013 at 09:53 PM 0
Share

In both platforms. If the bundle was generated with iOS as target it causes the problem even on editor mode.

1 Reply

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by equalsequals · Jul 26, 2013 at 03:17 PM

My team recently experienced this as well.

We found that simply re-assigning the material's shader at run-time with Shader.Find actually resolved the issue.

 [RequireComponent(typeof(Renderer))]
 public class ShaderFix : MonoBehaviour 
 {
     //This should be attached to any Game Object with a Renderer that has a Material with a custom shader.
     #if UNITY_IPHONE
     void Awake()
     {
 
         Material[] newMats = new Material[renderer.materials.Length];
         
         for(int i = 0; i < newMats.Length; i++)
         {
             Material ogMat = renderer.materials[i];
             Material mat = new Material(ogMat);
             //Note: the material maintains a link to its shader's name, so pass that across dynamically.
             mat.shader = Shader.Find(ogMat.shader.name); 
             newMats[i] = mat;
         }
         
         renderer.materials = newMats;
     }
     #endif    
 }

Another thing that may also provide some help is to have empty materials somewhere in a built scene that use the shaders.

The problem seems to be that since the shaders get bundled, they don't come across in the build because they weren't used anywhere that the build process could see. Creating a simple empty MonoBehaviour with a Material[] will suffice here, and they will not add any significant memory as they don't need textures, but just a way to ground the custom shader in your project so that it is collected by the build processor.

Hope this helps.

==

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 hvilela · Jul 26, 2013 at 05:36 PM 0
Share

Thanks! I still don't know why it happens (an Unity Bug, maybe) but at least now I have an workaround.

$$anonymous$$aybe you also have an answer to my other Asset Bundle question: http://answers.unity3d.com/questions/498393/assetbundle-content.html

Thanks again.

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

16 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Asset Bundles with In-App Payment in Unity Mobile 1 Answer

Animator in assetbundle from iphone app not play 1 Answer

Using AssetBundles as IAP Crashing 0 Answers

AssetBundles on iOS: Memory always increases, causing crash 0 Answers

Does Apple allow you to download assetbundles with scriptableobjects, from an external server? 0 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