Compare texture by content


I have a kind of a problem. I have multiple materials using the same texture. So the texture actually is exactly the same but I have imported it several times with each 3d object and with each model it also have a different name. So I was wondering whether I could write some kind of script, which does not compare the name of the textures but the content of the textures. like the different pixels or so, but I couldn’t find anything helpful in the script references.

Use GetPixels

Your textures will need to have read/write enabled in the importing settings to use GetPixels. However be warned this is not going to be very efficient, checking every pixel could be a lot of work if the image is large. An alternative would be to generate a unique hash code from the pixels(perhaps an editor script?) and store that for each texture. Then at runtime just compare the hashes.