Trouble with positioning

2D project. I have a GameObject which I use like a container. Rect position is middle-center. While the game is going I add some objects inside this container, hovewer the size doesn’t change. It is 0px widht and height. I have choosen another way to put it right in the center - I know how many object inside this container also I know width and heigth of them. I calculate whole width and whole heigth then divide it on 2 and calculate new Vector3 position in this way:
int horizontalLinesNum = horizontalLines[0].Count;
int verticalLinesNum = verticalLines[0].Count;

float newX = -(horizontalLinesNum*LINE_WIDTH) / 2;
float newY = (verticalLinesNum*LINE_WIDTH) / 2;

Vector3 newPosition = new Vector3 (newX, newY, 0);
this.transform.position = newPosition;

I’ve checked values in debug. It calculates newX = -162; newY = 162; Container appears, but not in posiotion(-162, 162,0). It appears in position(-188.3721, -353.4884, 0);

HOW COME? I can’t understand where it got this numbers. I have stucked with this for a three days. It blows my mind. Guys, please help.

It seems there are other things going on that affect your object position after you set it. You can try to set the position in LateUpdate, so it’s the last position setting that happens.

I changed the main Canvas to not have the same size on all devices. So,it has scale 1,1,1 now.

After I added a new GameObject at first it was put not in Canvas in position 0,0,0. After I changed parent, coords were changed to new binded to global coords. Now I set localPosition of GameObject and it is ok now.

Now I am able to move these objects properly on my screen!!!