Image.sprite/overrideSprite not changing

Hello,

I’m using the following line of code to change an UI image’s source image to a different image.

_boxObject.transform.FindChild("BoxCornerImage").transform.GetComponent<Image>().overrideSprite = spriteScript._ArrayOfSprites[SearchForValueInArray(spriteScript._arrayOfSprites, sprite)];

I know the method responsible for setting the image is working correctly, so the problem doesn’t lie there.

According to the inspector, the source image has been changed. But the old image is still displayed in the editor.

Is this a bug?

(Unity 4.6 v20)

Got it working,

The method I was calling to calculate which index was to be used was wrong.

Works as intended now.

Hi subwayheaven,

i wonder hot you got it to work,
i got the same problem,

even when i get the name of the Sprite it return me the old sprite name

myAnimal.GetChild(0).transform.GetChild(2).GetComponent().overrideSprite = myNewAnimal;
Debug.Log ("-----Sprite name) = " + myAnimal[0].GetChild (0).transform.GetChild (2).GetComponent ().sprite.name);
let say original sprite was a dog image
i overrideSprite with a cat image,
when i ask for the name of the sprite it the dog image name

well it was simple ,

for other people that might need this
instead of using “.overrideSprite =” just use “.sprite =”

:slight_smile: