- Home /
Use different material based on target platform
I'm making a game which I intend to be cross platform. I was running into performance problems on mobile and after testing a bit found if I used the legacy mobile diffuse shader it ran significantly better.
My question is, is there a way to specify different materials based on the target platform?
I would like to use my fancy normal mapped specular for Win/Mac/Linux and mobile diffuse for iOS/Android.
Answer by ttRevan · Nov 05, 2015 at 10:42 AM
You can use conditional compilation to include assets only for target platform:
public class ExampleClass : MonoBehaviour {
#if UNITY_EDITOR || UNITY_ANDROID
Material androidMaterial;
#endif
#if UNITY_EDITOR || UNITY_STANDALONE
Material standaloneMaterial;
#endif
Material material;
void Start() {
#if UNITY_EDITOR || UNITY_STANDALONE
material = standaloneMaterial;
#elif UNITY_ANDROID
material = androidMaterial;
#endif
}
}
Thank you very much for your response,
This does change the material at runtime. I did read that having a material assigned to the object in the prefab then changing it at runtime creates garbage which negatively impacts performance. I will perform some tests along these lines and report back as to the performance.
Your answer
Follow this Question
Related Questions
Problem with rendering of standard material on iOs platform. 0 Answers
why lwrp is very slow? 0 Answers
Performance Optimization for Mobile 3D, No Static 2 Answers
Prevent material from rendering behind itself 0 Answers
Standard Shader Vs Mobile Diffuse Shader 0 Answers