Retrieving Source Image from UI object in c#

Hi all

I am trying to retrieve the Source Image value from a ui object at runtime. The ui object gets assigned a sprite at runtime and is only ever in the range of 1-6. I am using c# to code this and have tried the following, but it only returns the object’s name

panelASpriteName = panelA.GetComponentInChildren<Image>().name;

please see attached images 62962-capture.png

Guess panelA.GetComponentInChildren<Image>().sprite is what you looking for.

Because you literally asked for the name instead of the sprite?

public Sprite panelASprite;

void Start(){
    panelASprite = panelA.GetComponentInChildren<Image>().sprite;
}

You wrote …Children().name when it should be sprite

Thank you both. What worked for me was :

panelAtemp = panelA.GetComponentInChildren<Image>().sprite.name;