Question by
ThiagoFerza · Jun 17, 2020 at 05:42 AM ·
gameobjectspriteparent-childpivotlocalposition
Sprite changes the child local position,Sprite pivot change Vector3.zero postion of child gameObject
Hi guys! I found a behavior that I thought it was weird and did find no clues about. If I create a Game Object, add a Sprite Renderer with a Sprite and add a child by Script like this:
private void Awake() {
GameObject child = new GameObject();
child.transform.SetParent(parent.transform);
child.transform.localPosition = Vector3.zero;
}
The position of the child (0,0,0) is set to the Sprite pivot position and not to the parent transform position. I tested using other positions to the pivot. Why this is happening? (Unity version: 2019.3.7f1)
Thank you all in advance.
Comment
Answer by ThiagoFerza · Jun 18, 2020 at 01:15 AM
I think I get It. The game object and the Sprite are seen as one entity. So the Sprite pivot become the position (0,0,0) of the parent, for the point of view of it's children. I must thanks the Youtuber Code Monkey for the video that clarifies It.