I read many questions about this, but I still can\'t find what my problem is... I\'m trying to instantiate a prefab at the canvas. It is compose of a button and a sprite. Th
SpriteRenderer is not made to be used with the Canvas. You are confusing and misusing the two.
SpriteRenderer
is used for displaying 2D Objects like a 2D animated character or a 2D environment. You can attach Rigidbody2D
and Colliders
to SpriteRenderer
.
Canvas is used for UI display only. It is used for displaying things such as UI texts, buttons, sliders, scrollbars and images. You shouldn't attach Rigidbody2D and Colliders to it or its child objects.
With the explanation above, you should be able to determine which one to use. If you just need to display image under a Canvas, use the Image, or RawImage component since they are part of the UI system. This should work but do not make SpriteRenderer
a child of a Canvas. If you have to use SpriteRenderer
, make it its own object or under another object but it should not be under a Canvas. You may find Unity's UI tutorial useful.