- Home /
Compare texture by content
Hey,
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.
Answer by karljj1 · Jun 06, 2014 at 04:24 PM
Use GetPixels
http://docs.unity3d.com/ScriptReference/Texture2D.GetPixels.html
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.
Answer by arturmandas · Oct 26, 2020 at 12:21 PM
This seemed to work fine for me, and it should be much faster than comparing pixel by pixel.
Your answer
Follow this Question
Related Questions
Assigning UV Map to model at runtime 0 Answers
Issue with too much Vram occupation 0 Answers
[LF Tutorials/Courses] Texturing & 3D 0 Answers
How can I - Display camera view from scene in another scene? 2 Answers