Hola!
Just found a strange behaviour... If I instantiate a gameObject @runtime (same as duplicate, CTRL+D, in editor) which has a "Simple Texture" (UITexture) attached, any changes made to the UITexture.mainTexture on a duplicate will affect all other duplicates' textures (you with me?
).
Basically:
- Create a "Simple Texture" with a UITexture.
- Duplicate multiple times (@runtime) using GameObject.Instantiate(gameObjectWithUITexture) as GameObject;
or just CTRL+D on the gameObject.
Change mainTexture (from code) of any of the instances, see how the texture changes for ALL the instances.
Now, this is not my area of expertice, but I found that the material (mMat in UIWidget) is not being null'd when duplicated, thus all duplicates reference the same material! I fixed it quickly by setting UIWidget.material to null in Awake() in UITexture, but I sense there might be something I'm missing about you caching the material in the first place (to tired to find out)...
Anyways, without rabbling about stuff I don't know, this is my quickfix (in UITexture):
override protected void Awake(){
base.Awake();
material = null;
}
//This will make it create a new instance next time mainTexture is set for the duplicated object
[mainTexture...]
if (mMat == null)
{
mDynamicMat
= new Material
(shader
); mDynamicMat.hideFlags = HideFlags.DontSave;
mMat = mDynamicMat;
}
[...]
This will make sure that the material is allways new'd for each new UITexture.
Sorry for not looking into this more thoroughly before posting, just felt lazy today. 