- Home /
Why gameObj's pos changes when a child is added ?
http://prntscr.com/5ftxwq -1st screenshot
http://prntscr.com/5ftz66 -2nd screenshot
http://prntscr.com/5ftzhq -3rd screenshot
http://prntscr.com/5fu5ls -4th screenshot
http://prntscr.com/5fu6cw -5th screenshot
GameObject's position is 000 all the time but when a child being added to it, it changes its position somehow as if it was the child not the parent and it's 000 pos becomes in the center of the PlatformLongest gameObject not in the center of the screen. To see this you can just switch fast between the 1st and the 3rd screenshot.
Also when I add another gameObj to the parent (PlatformShort in this case) the parent gameObj's position goes between the 2 children positiion. You can see this by switching between the 4th and the 5th screenshot.
Please if anybody can help me.. it doesn't look like something very buggy just probably I don't understand how it works.
Answer by EvilTak · Dec 12, 2014 at 01:26 AM
GameObject is an empty game object. Since it has only one child, it's position will be the center of that child. If it has two or more children, a bounds encapsulating all of them is created, and the position of the parent object will be the center of that bounds.
Thanks! Does this work like this any time without exceptions ?
If the parent has any collider, mesh, etc. The bounds will take that into account too.
Answer by Owen-Reynolds · Dec 12, 2014 at 04:46 AM
The actual position isn't changing. You can even see that it's always (0,0,0) in the Inspector. The editor is just trying to be helpful by moving the handles to the center of the object, just to make it easier to find.
See the small button in the upperish left that says "Center", next to "Local"? If you click it to "Pivot" the handles will stay at the actual position. Of course, it has no effect on game play.
Your answer
Follow this Question
Related Questions
Make a simple tree 1 Answer
Child selection forces parent selection 1 Answer
Why is parenting not working? 0 Answers
Get Child from a parent 3 Answers
Destroying of parent causes issues for OnDestroy() in children 0 Answers