Couple of things here…
- Please read this page about how to post code on the forums nicely: Using code tags properly
- rather than try to figure out what’s the matter right now with your code, what do you say to trying by creating this object you desire, making it a prefab, and then referencing it to be instantiated instead of all that code?
Don’t get me wrong, I love code… I’m just saying maybe give that a shot.
One note, though, I thought it wasn’t possible to add a rect transform to an object. One would just be assigned automatically if you add an appropriate object to a canvas (such as a panel).