I have a Canvas GameObject with a panel inside of it and a button prefab of the default button.
When I drag the button from my resources folder onto the Canvas in the hierarchy, it places itself where I expect it to, into the panel.
However when I instantiate it like below:
GameObject button = Instantiate(Resources.Load("UI/Dialogue/Button"), new Vector3(0, 0, 0), Quaternion.identity, MyCanvas.transform) as GameObject;
it gets placed into the center of the screen because of the second parameter. However, I can't set it as a child of the parent because that doesn't happen until the last parameter. It also doesn't feel right to figure out the exact Vector3 to plug in so that it looks like its on top of the panel.
Is there a way to instantiate the button onto the panel in code as it works when dragging it from the resources folder onto the Canvas in the hierarchy?