Performance: Material properties
Material properties affect rendering speed and GPU workload by controlling how surfaces look and react to light.
Material sharedMat = Resources.Load<Material>("RedMaterial"); // Reuse sharedMat for all objects needing the same look
Material mat = new Material(Shader.Find("Standard")); mat.SetFloat("_Glossiness", 1.0f); mat.SetColor("_Color", Color.red); // Applying unique material instance per object
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Unique material per object | N/A | N/A | High GPU cost per object | [X] Bad |
| Shared material reused | N/A | N/A | Lower GPU cost, fewer draw calls | [OK] Good |
renderer.material.color control in Unity?color inside renderer.material refers to the color attribute of the material.Color.red or new Color(float r, float g, float b) with values between 0 and 1.Color.red correctly. renderer.material.color = "red"; uses a string which is invalid. renderer.material.color = new Color(255, 0, 0); uses integers 255 which is incorrect for Color. renderer.material.color = Color(1, 0, 0); misses new keyword and uses wrong syntax.renderer.material.color = new Color(0.5f, 0.2f, 0.7f);
renderer.material.shininess = 0.8f;
renderer.material.SetFloat("_Glossiness", 0.8f); to change shininess.newTexture?mainTexture property.newTexture to mainTexture. renderer.material.color = newTexture; wrongly assigns texture to color. renderer.material.SetColor("_MainTex", newTexture); uses SetColor with a texture which is invalid. renderer.material.texture = newTexture; uses a non-existent 'texture' property.Pass the test and this pattern moves unknown