Setting parent of instantiated sprite

I’m trying to instantiate indicator sprites to my UI, which for some reason doesnt work. I made prefabs of them and now I’m trying to instantiate them with the following commands:

public Sprite indicatorR;

Sprite rightIndicator;

rightIndicator = Instantiate(indicatorR) as Sprite;

 rightIndicator.name = "indicatorImageR";
 rightIndicator.transform.parent = canvas.transform;

Sadly, Unity tells me that Sprites don’t have a definition for “transform”, so this for some reason doesn’t work.

What do I have to do instead?

thanks C:

a sprite goes onto a spriterenderer, which must be a component on a gameobject. either assign the sprite to an existing SpriteRenderer, or you make the whole gameobject a prefab (saves you the code for assignment and stuff) and instantiate that. If you’re using UGUI for that, than you mixed this up with Image, which is the UGUI component. same advice from my side, but setting the parent would the need the call SetParent(parenttransform, false)

Hello,
Maybe you should instantiate a GameObject with an Image Component (or Sprite Component if it’s not a UI element) directly.