Set pixel resets each time I run the game.

I have a very simple texture and I use texture.SetPixel to change color of some pixels,it works fine but each time I close the game and run it again , texture gets back to the original texutre, How can I fix it ?!

Is this an editor script? Or something happening during runtime? In either case you’ll likely need to dirty the asset so Unity knows it’s been changed.

1 Like

It happens during runtime . Could you please explain a little more?

1 Like

Unity cannot modify an original texture on disk using SetPixel, eg, like a PNG or JPG file you are importing.

When you use SetPixel on an imported Read/Write enabled texture the actual behavior is undefined, but generally it will remain changed for the current run session, or at least until that asset is marked as unused, gets unloaded and then reloaded from the original AssetDatabase.

You can write an editor script that loads and manipulates a texture, but you would need to essentially resave it as a new PNG / JPG / whatever file and tell Unity to reimport it afterwards.

2 Likes