Material Cloning Issues

Alright, what I’m trying to do, I’ve done before in the past long ago. Can’t remember how it’s done properly. There are many threads on here addressing my issue, but none of the solutions are working for me.

I’m using GetPixels and SetPixels to draw a decal right on the desired texture/material. However, in my case using a vehicle, all 8 tires use the same material/texture. So a decal drawn on one, draws on them all. Which I expected. I tried many solutions to instantiate a unique material/texture for each tire (or any other part for that matter) with no luck.

The following is the code currently (which as you can see is trying very hard to make the new tex/mat unique). It didn’t used to be that convoluted, but after each help post I read, it slowly became that way.

code: http://paste.ofcode.org/q9YmKuMG3KXq9JHiRMxZFP

With the current code, nothing shows up at all, with original code it behaved the exact way I’m attempting to prevent.

Attached is a screen shot showing the original issue. (only one tire was actually clicked on).

Your help is much appreciated.

If you want a unique texture for each tire generated at runtime, in the Start() on a script attached to each tire do:

renderer.material.mainTexture = Instantiate(renderer.material.mainTexture) as Texture;

In unity, if you make any runtime changes to a material, Unity generates a new material instance. The line of code above makes a copy of the texture, so each tire will have both a unique material and a unique texture.