- Home /
The question is answered, right answer was accepted
Accessing material.color removes the material...
I have a single normal Diffuse material on an object. Getting or setting the color on this material at runtime causes the material to no longer be assigned to the Mesh Renderer component... what am I missing?
Color defaultColor = renderer.material.color;
or
renderer.material.color = new Color(1f, 1f, 1f);
Any time you change a material property at runtime, you get a new material instance, but that material should revert back to the original once you stop your app. What are you seeing?
I'm really just trying to get the color of the material on a prefab and store it once. Is there not a way to simply check this data without creating a new material instance?
Anyway, it doesn't revert back to the original when stopping the app, but I've found this is because I'm editing a prefab on disk and not an object in the Scene hierarchy.
Would be nice if edits to prefabs were treated in a similar way though (maybe marking the prefab in some way to indicate this behavior). Additionally, when closing unity without saving, it would ideally revert edits to prefabs as well (potentially off the same setting). Thank god for source control!
Answer by Sidno · Nov 27, 2014 at 03:42 AM
The answer is renderer.sharedMaterial:
http://docs.unity3d.com/Manual/DrawCallBatching.html (Materials section)
http://docs.unity3d.com/ScriptReference/Renderer-sharedMaterial.html
Got to love sneaky quirks!
Follow this Question
Related Questions
Material doesn't have a color property '_Color' 4 Answers
Changing two different objects renderer colour 1 Answer
GameObjects color changes on initial load, just not afterwards. 1 Answer
Adjust tint color of particles/additive? 2 Answers
MeshRenderer.material.color not changing inside if statement but is outside if statement? 1 Answer