'Is this transform being positioned properly?

I am trying to create a new Transform with the same position as my already existing RectTransform through code.

        if (item.rowIndex != -1 && item.columnIndex == 0) {
            Debug.Log(item.transform.localPosition);
            GameObject transformGO = new GameObject("Transform #" + (transformsCount + 1));
            transformGO.transform.SetParent(transform, true);
            transformGO.transform.localPosition = new Vector2(item.rectTransform.localPosition.x, item.rectTransform.localPosition.y);
            possiblePositions[transformsCount] = transformGO.transform;
            transformsCount++;
        }

The visual I see on the editor does not match what I thought was going to happen (I want the transform to be centered in the middle of the object). Is this just a visual bug or is the newly created transform not actually at the correct position?

RectTransform position

Transform position



Solution 1:[1]

I was not setting the parent correctly. It is working fine now.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Nicolas Cinq-Mars