I tried ShaderVariantCollection to collect variants and put SVC and relevent shaders into one AssetBundle. At runtime I loaded the shader bundle, got svc and warmed up, then loaded some materials using diffferent variants. 2 out of 4 materials failed to find correct variants. Variants are defined as: #pragma shader_feature _ RED BLUE GREEN and SVC include 4 variants: Normal <no keywords> Normal RED Normal GREEN Normal BLUE the last 2 failed. Unity version: 5.5.2 & 5.6.0 Anyone have some idea how to fix this?
I noticed that if you use shader_feature and your shader is a different bundle that your materials the shader will get stripped has if there was no keyword used. Solutions I found was to either use multi_compile instead, but this will make the shader file much bigger depending on how many variations you have, or include a material using the shader variant you want in the same bundle than the shaders. I though that shader variant was to prevent that too, but looks like it's not working atm. I saw some post where a guy from unity said that they are working on a fix for that though.
Thank you very much Yan, it works exactly as you suggested. I consulted some unity guy and he mentioned (compiled/optimized) shader variant code is saved with material. he suggested me use ShaderVariantCollection. Hope this bug could be fixed soon!