- Home /
Duplicating Gameobject and changing it without affecting original Gameobject
Hi. I duplicate a Gameobject and want to change one of its material. But when i change it,the material of original Gameobject changes. I want the material of original Gameobject don't change. How can i do it?
Answer by Piflik · Jul 19, 2012 at 12:24 PM
You have to assign a separate Material to the object. (If I deciphered your question correctly)
It's odd though right? At runtime using material should automatically create a new instance of the material.
@vahid62 - are you using material or shared$$anonymous$$aterial
Seems like there should be a GameObject.BreakPrefabLink() function.
This has nothing to do with prefabs. $$anonymous$$aterials are always seperate assets at edittime. In the editor you always work with shared$$anonymous$$aterials (in the inspector for example). The renderer uses just this asset as material. At runtime however each rendererwill duplicate the material when you access .material. That's why you can't or shouldn't access .material in the editor. This will leak the duplicated material since it isn't stored anywhere as asset.
So you have to duplicate the material as well or create an entirely new one and assign this to your duplicated renderer.
Your answer
Follow this Question
Related Questions
How to have different materials on one GameObject? 1 Answer
Material class use general question 1 Answer
Fading a GameObject in/out 1 Answer
Shader that makes object transparent as light hits it 0 Answers
Select colour then change texture 0 Answers