- Home /
How to change the colour of a prefab back to default to save draw call
Hi, In my game I need to change the colour of a prefab for a certain amount of time, which obviously then increases the number of draw calls, how would i change it back the the prefabs default later to then decrease the draw calls?
thanks in advance.
Why don't you save the original color on a variable before changing it? Then you can just return to the original one.
You might try caching the original shared$$anonymous$$aterial, then re-using it once you're done (example). I haven't tried this, so I don't know for sure if it will still save your draw calls.
Depending on the object, you could change the color using a shader that supports vertex colors and change the color by changing the colors array in the mesh. That way even objects with different colors will batch.
And if you try @rutter's suggestion, let us know if it works.
Thanks rutter , I just tried that now and it doesnt seem to help. I did notice something weird though, if you store the material of the prefab (not apply or change) then the draw calls increase too. seems very odd
Answer by Eric5h5 · Aug 27, 2014 at 06:25 PM
Once you've changed the color, you've created a new material instance, so just changing the color back will have no effect since you're still using the new material instance. The best thing is not to create new material instances, which will require other techniques such as vertex colors or texture atlases. (The color property for sprites, for example, uses vertex colors.)
Or, depending on what you're doing, it may be feasible to manually create one or more material instances yourself, then change the color of those instances and use sharedMaterial to assign them as needed. So you'd never use renderer.material, only renderer.sharedMaterial.
GetComponent<SpriteRenderer>().color = new color
that did the trick. Thanks
Your answer
Follow this Question
Related Questions
Designing Levels in 3DS Max? 1 Answer
Display Item Sprite on Inventory UI 1 Answer
Please help with beginner Prefab & OnMouseDown 1 Answer
Add Asset Bundle Name to a prefab in "Editor Code" 1 Answer
Prefab of a prefab? 4 Answers