Quantcast
Channel: Answers for "memory consumption when changing materials [iOS]"
Viewing all articles
Browse latest Browse all 6

Answer by Bunny83

$
0
0
Right, just read the docs on [Renderer.material][1] and don't skip the "important note". Whenever you read or write to renderer.material, Unity will duplicate the material so this renderer has it's own instance. Once a renderer has a unique instance it will keep it. This will actually break any batching since each tile you click will now have a unique material. What you actually want to do is this: if (...) renderer.sharedMaterial = attackMat; else if (...) renderer.sharedMaterial = validMoveMat; "sharedMaterial" will return a reference to the shared Material instance. When you set the sharedMaterial Unity will save the reference and will not duplicate the material. Keep in mind that since the different objects share the same material, any changes on the material itself will affect all objects that use this material. Note by change **on** the material i mean things like: attackMat.color = xxx; attackMat.mainTexture = xxx; attackMat.shader = xxx; attackMat.SetXXX(...); [1]: http://docs.unity3d.com/Documentation/ScriptReference/Renderer-material.html

Viewing all articles
Browse latest Browse all 6

Latest Images

Trending Articles





Latest Images