How can i permanently change source image via script?

Hi.

I tried those 2 options but none of them works for me as i wanted.

GameObject.Find(“MyImage”).GetComponent().sprite = newBackgroundSprite;
GameObject.Find(“MyImage”).GetComponent().overrideSprite = newBackgroundSprite;

I want to be able to setup new sprite in script and image component source image should be permanently overwritten by this new sprite.

Can you help me somehow?

for the most part changes applied during runtime to monobehaviours only exist within that instance of runtime, they are rolled back when the runtime ends.

having said that scriptableobjects are permanently updated when they have their values changed during runtime… you might also be able to store the updated data in playerprefs and read from there instead depending on what you are trying to achieve.

You’re basically looking at a data storage approach.

when are where are you running this code? Anything you do in play mode that is part of the scene will get reverted wehn leaving play mode. But if you run it from a editor script, it will save.