Change Unity 4.6 UI Image element's sprite via script?

Hi there! I’m using the following code to generate a series of buttons with images on top of them, which for the most part is working fine:

function RedefineScrollbar()
{
	for(var i=0;i<curComponents.length;i++)
	{
		var newButton = Instantiate(componentButton,Vector3(0,0,0),Quaternion.identity);
		newButton.parent=shipComponentHolder;
		var thumb : RectTransform = newButton.Find("Thumbnail");
		thumb.GetComponent(UnityEngine.UI.Image).sprite = curComponents*.thumbnail;*
  • }*
    }
    This compiles fine, but the last line causes the following error on every frame:
    MissingReferenceException: The object of type ‘Sprite’ has been destroyed but you are still trying to access it.
    Here’s what the image I’m accessing looks like as a prefab:
    http://i.imgur.com/CLbrQJv.jpg
    And here is the jumbled mess it looks like as it actually gets instantiated:
    http://i.imgur.com/hnkCpjM.jpg
    Any insight as to why this is happening would be greatly appreciated!

here is solution

public Sprite mySprites;

    public void Start()
    {
        GetComponent<UnityEngine.UI.Image>().sprite = mySprites;
    }

Hi, I’m modifying Image.overrideSprite and it works well.