- Home /
UI elements rounding position to parent gameobject
Hello,
I've been working on a game and one annoying thing I've found is that when I moved a gameobject that is a parent to, say, a button, when I moved the parent gamobject the child button seems to snap in to place when I move it, as if it were snapping on to a grid.
Now while I'll mention that I'm working with small numbers, they aren't astronomically low (I'm working with coordinates at or below 1)
It's not easily noticeable, but I'm trying to get the position of the parent gameobject just right (it's a pause button that I'm putting on the top-right corner) and so it would make sense that I wouldn't want the pause button to be slightly off of the position.
Can anyone lend me some help on this?
Answer by Jwizard93 · Jul 05, 2017 at 10:17 PM
If the child object is meant to be in the same place as the parent object then make sure the child's location is 0,0,0. Child transforms are relative to their parent.
Well yeah, that's the problem.
I have a normal gameobject and a UI element. The UI element is child to the parent gameobject. Let's say I put the gameobject's position to 0,0,0. and then the UI element to the same area.
Now let's say I put the gameobject to 0, 0.5, 0. The UI element's position is still 0,0,0. But, when I move the gameobject to 0,2,0, the UI element suddenly jumps up to something like 0,1.5,0.
Basically what I'm saying is the UI element is acting as if it is snapping to a grid. I don't get the same results when the child object is just another normal gameobject.
Of course, my mistake.
So now I'm thinking maybe it's an anchors thing. There should be a component of the UI elements called RectTransform. That component should have public fields called anchors. Adjusting those anchors adjusts how the UI element reacts to properties of its parent gameObject. Have you tried playing around with that? I found that info here in this list of tweets. There's a lot more comprehensive UI tut out there, but this seems a good place to learn the key words you need to know about.
Your answer
![](https://koobas.hobune.stream/wayback/20220612125614im_/https://answers.unity.com/themes/thub/images/avi.jpg)