Change mainTexture of new Instantiate

But keep previous Instantiate’s texture the same…?

I’m completely stumped by this, I can instance the same object with a different texture but the issues comes when it changes the previous instance’s texture.

An example of what I mean is, instantiating a prefab called Chap, like: Instantiate (Chap) with a blue texture, then Instantiate (Chap) again, with a pink texture… Make sense?

Anyone have any ideas or any links to code references that might help?

EDIT: Sorry, I’m not being very clear I’m having trouble explaining what I mean. I have a prefab of a person, with an unlit blue texture, I want to be able to instantiate the same prefab, in a different place with a different texture.

var Selected : int = 0;
var Jeff : GameObject;
var Blue : Texture;
var Pink : Texture;

function OnMouseUp (){
    if (Selected == 1){
        Instantiate (Jeff);
        Jeff.renderer.material.mainTexture = Blue;
    if (Selected == 2){
        Instantiate (Jeff);
        Jeff.renderer.material.mainTexture = Pink;

The problem is with not changing the previous instatantiated texture aswell. Probably should have mentioned in JavaScript, so I apologize for that.

Hi There! If I understand what you’re saying, you want multiple instantiated objects with the same texture? That is quite possible. Here’s a quick demo (requires a gameobject and 3 textures).

using UnityEngine;

public class lol : MonoBehaviour

public GameObject MyPrefab;
public Texture[] Textures = new Texture[] { null, null, null };
private GameObject[] _prefabs = new GameObject[3];
void Start()
    _prefabs[0] = (GameObject)Instantiate(MyPrefab,, new Quaternion(0, 0, 0, 0));
    _prefabs[1] = (GameObject)Instantiate(MyPrefab, Vector3.left, new Quaternion(0, 0, 0, 0));
    _prefabs[2] = (GameObject)Instantiate(MyPrefab, Vector3.right, new Quaternion(0, 0, 0, 0));

    for (int i = 0; i < _prefabs.Length; i++)
        GameObject prefab = _prefabs*;*

prefab.GetComponent().material.mainTexture = Textures*;*
Here’s some things to note: Each time you change the texture on a gameobject when unity is running, Unity creates a temporary instantiated material of that object. This means your changes don’t go to the hard drive, and you’re pretty much making each object completely seperate (think individual draw-calls if you want to use this on a phone or iPad in the future).
You can’t directly access an objects material, as it is rendered through either a Mesh Renderer or Skinned Mesh Renderer (for characters). A material isn’t a component, so you can’t use GetComponent on it directly.

Aha! Managed to find some code already posted here that pretty much did what I need:

function changeMaterial01(){
    var changeMaterial01 : Material = Jeff.renderer.material;
    Jeff.renderer.material = Material01;