Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
12 Jun 22 - 14 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 Flassari · Nov 11, 2016 at 02:30 PM · shadershadersassetbundleassetbundles

Missing shader variants/features in asset bundles

When I put all my shaders into an assetbundle Unity will stop determining which shaderfeatures are being used and not include any of them. ShaderVariantCollection doesn't seem to help at all when it comes to including variants of the shader in assetbundles.

It seems it only detects which shaderfeatures I'm using if the materials are in the same asset bundle as the shader itself, so I've managed to hack around it by just creating dummy materials of all the shader variants used in the project and putting them in the assetbundle. It works perfectly but seems hackish and I'm wondering if there's some better/proper way of doing it.

Comment
Add comment · Show 3
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 tanoshimi · Nov 11, 2016 at 04:11 PM 0
Share

From your description, that's exactly what ShaderVariantCollection should do, although I admit I haven't tested it in an assetbundle (though it works for me for shader variants that are swapped in at runtime on a base project)

avatar image amarchand · Nov 15, 2016 at 10:24 AM 0
Share

It might be because "features" are meant to be stripped if they aren't explicitly used in materials. However, "variants" are always generated, since they can be enabled by code. From documentation:

pragma shader_feature is very similar to #pragma multi_compile, the only difference is that unused variants of shader_feature shaders will not be included into game build. So shader_feature makes most sense for keywords that will be set on the materials, while multi_compile for keywords that will be set from code globally.

(There is an exception with fog and lightmap variants since they are stripped if not explicitly used or enabled in graphics settings)

avatar image Flassari · Nov 15, 2016 at 10:44 AM 0
Share

That's definitely the problem, Unity isn't marking the shader features as "in use", but there has to be some way of telling Unity what shader features to include if the shaders are being built into bundles, specially since it works fine if I don't put them into asset bundles.

I'm using too many features to have them be multi_compiled, as the exponential variations of the shader would blow out of proportions and the shaders would become practically un-buildable.

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by MikeHergaarden · Jan 04, 2017 at 09:49 AM

While multi_compile "fixes" this, it will generate ALL variants which is not what you want unless you really cant predict what features your code will use on the shader.

Including the variants in a shadervariants bundle does not fix this issue in 5.4 or 5.5.0p3: unity will still strip out the shader feature.

Solution

@Flassari What DOES work is explicitly assigning the offending material (that is using _ALPHABLEND_ON for example) to an assetbundle. Only then Unity will find the usage of the shader features and no longer strip it. Unity does NOT lookup the shader features of "simple" referenced materials in assetbundles.

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 Flassari · Jan 04, 2017 at 11:29 AM 0
Share

The materials can't even be assigned to just any asset bundle, they have to be assigned to the same asset bundle that the shader is in. I guess the dummy material hack is still right now the best solution.

avatar image
0

Answer by hearstzhang · Jun 14, 2019 at 05:32 PM

hey @MikeHergaarden your solution seems useless even I include shader variant collection file, or include material which enabled the keywords that I want. If the target scene remains unopened, the build assetbundle result will strip shader variants which I wanted. The only way to avoid this is select every shader variant from Graphics Settings, which will result some built-in shaders (such as Standard shaders) become a 3MB monster, which will cause app crash because lack of memory when a lot of asset bundles referenced the standard shader.

Comment
Add comment · 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

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

84 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 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 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 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 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 avatar image avatar image avatar image avatar image

Related Questions

Unity 5 import Shader changed to Standard from Diffuse 1 Answer

How to do an outline shader?,How to do an outline? 0 Answers

Shader Problem 0 Answers

How is _WorldSpaceLightPos0 calculated for a directional light? 0 Answers

shader problem 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