i am having all manner of totally mind blowing weird things happen when I try to do this…
First off, I do this:
public RectTransform ScrollRegion;
void Start()
{
ScrollRegion.rect.Set(5, 5, 5, 5);
}
As noted aove, the size remains unchanged at PosX 0, PosY 0, PosZ 0, Width 1700 and Height 166
Next, I print the localPosition and position of the RectTransform set as the Content for the ScrollRect. It’s coordinates are the ones I mentioned above… 0,0,0 and 1700, 166 and the anchors are set to stretch vertically and anchor to the left. Anchors min 0 and 0.5, max 0 and 0.5, pivot 0 and 0.5… So why in the world does the localPosition print off as -468,0,0 and the position as 279.8, 111.7.0 ???
Where the hell does that -468 and 279 come from???
But even more interestingly… I have an Image component with a bunch of child objects that I created a prefab from. When I instantiate it, I do this:
float this_offset = GetComponent<RectTransform>().localPosition.x;
buttons = new WUNLockableButton[count];
for( int i = 0; i < count; i++)
{
buttons[i] = (WUNLockableButton)Instantiate(button_prefab);
buttons[i].transform.parent = transform;
buttons[i].transform.GetComponent<RectTransform>().position = new Vector3((i * 300f) - this_offset, 0f, 0f);
}
Notice how I already detract the parent’s x position from the local position of the child object as , by default, the localposition is wayyyyyyy far to the right… Now keep in mind I set the local position to 0 then detract a value from it and then notice how I start i with a value of 0 and each increment I add 300 to the x… So someone please explain to me why the first object created has this RectTransform values:

After that, each button loads 300 units apart as expected but why in the world does the first one have an offset of 188 when I clearly say the position.x must be 0 ???
When I change that code to set the localPosition, not the position, I get this

Mind you, when setting localPosition, the Top and Bottom are both set to 83 but because the image gets stretched, that make absolutely no difference to the final image and when I change that to 0 and 0 the image looks identical so even though I have no idea why it is set to 83 in the first place, at least it works…
On the other hand, when i set the position, the Top becomes 194 and the bottom becomes -28 resulting in most of the image being clipped.
Why ? what is going on here???
How am I supposed to position RectTransform objects under parents without this kind of magic numbers appearing out of thin air?