- Home /
[4.6 UI] how to move a button *AND* its anchors ?
Hello Everyone, Am still not used to the new UI framework and and kinda a bit confused on how anchors work, for now i want to know if there is a way to make the anchors move relatively to their "owners" not the parent of the game object, in the GIF below i move the button and then was forced to move each of the anchors manually, is there a solution for this ?
PS: i can move anchors and button at the same time using the shift button, but only when the anchors are all "connected" together, what i need is to make the anchor stretched on the actual game object (i don't know why when i choose the preset streched option it stretch the anchors to the parent)
Thank you
There are a couple of little buttons on the RectTransform component that may help
Answer by Yasser34 · Dec 20, 2014 at 04:08 AM
Hi, you can put your button inside a panel then add a Layout to this panel, ex: "VerticalLayout" : like this the button will be fixed with the Anchors also, and the job is done.
my button is already inside a panel, but what do you mean apply a Layout to this panel ? where can i do that ? for now i am using the solution in this question because that is what i need but i wonder why such a basic thing isn't available till now
So go to your panel and click : Add Component -> Vertical Layout Group. Yes this solution may help you i hope, when you add your Layout, go click on Padding so like this you can configure the paddings of your panel contents.
Thank you!! that was very helpful, but still there is a new problem now, when i run the game with "maximized on play" enabled, i get a wrong layout, also when i build and test on mobile, however if i run the game un-maximized, then enable that option again and pause->un-pause, everything is in its place, any idea please ?
So yes, that's normal : go check your Panel's rectTransform and change the relative resolution ex: if you want to stay on the top of your screen you have to check the top resize rectangle, before you do any build try to change on different resolutions in the game screen like this you can see how it will be on all of your devices.
The most important thing is that you must go verify and activate also on your canvas the auto-resize option : like this your canvas will be resized automatically with the output screen.
Answer by Sergey_Suslov · May 28, 2019 at 07:33 AM
Hold Crtl and Shift then drag anchor
This works but only if the pivot isn't sitting on top of the anchor. I have to move the pivot, then the object, then place the pivot back.
Answer by Develax · Feb 27, 2020 at 01:00 PM
Place the anchors to the center of the button, for example.
Then press Ctrl+Shift and drag one of the anchors slowly by mouse, this way everything (button and all its anchors) will be dragged simultaneously.