Search Unity

Image.sprite/overrideSprite not changing

Discussion in 'Unity UI (uGUI) & TextMesh Pro' started by subwayheaven, Oct 20, 2014.

  1. subwayheaven

    subwayheaven

    Joined:
    Oct 15, 2014
    Posts:
    10
    Hello,

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

    Code (CSharp):
    1. _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)

     
  2. subwayheaven

    subwayheaven

    Joined:
    Oct 15, 2014
    Posts:
    10
    Got it working,

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

    Works as intended now.
     
  3. Delta9

    Delta9

    Joined:
    Oct 7, 2014
    Posts:
    2
    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<Image>().overrideSprite = myNewAnimal;

    Debug.Log ("-----Sprite name) = " + myAnimal[0].GetChild (0).transform.GetChild (2).GetComponent<Image> ().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

     
  4. Delta9

    Delta9

    Joined:
    Oct 7, 2014
    Posts:
    2
    well it was simple ,

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


    :)