- Home /
Grid layout group changing anchors
Hi, I have got plenty of buttons as childs of mainButton, they are disabled before start and via script I'm enabling them. Problem is In mainButton object when I'm using Grid Layout Group, it's changing all child's Anchors to left up, i want to middle center, actually to make Grid Layout Group not changing that. I would like to not set up them via script because it will make a lot of changing in all code. Is there way to disable that function on Grid Layout Group, or maybe I should use something different?
Small question, why do you want the child anchors to be middle center? Because a grid layout group places it's childs on a grid on a fixed position and with a fixed size (starting in a given corner and on a given axis), anchors could in theory be set to anything but there is really no point as changing it would just cause the grid layout group to calculate the new x, y position and size values in order to place the child at exactly the same position... Because there is no point in wasting time to calculate that I would understand why it is set to a fixed corner. So what are you hoping to achieve by changing the anchor?
I'm taking at start theirs positions, then moving them somewhere, at end check if they back correctly. On screen everything is ok but values are different because anchors changes so position values too.
Ok, so because I'm still not able to graps why you want to do this, I'll just try to answer the original question, in the hope it helps you...
You are not able to change the anchors of the childs to middle center easilly. You could in theory make a script that extends GridLayoutGroup and overwrite the methods that set the anchors. (SetlayoutHorizontal) But you then would probably have to overwrite a lot more as the whole component assumes the anchors to be in the left top. If you want to do that, the source of GridLayoutGroup which is publically available is a good start. At lines 121/122 the anchors are set.
You probably should use somethng different. But because I don't know what the ultimate goal is of doing all the things you do here, I can't hep you with that...
Your answer
Follow this Question
Related Questions
How to Force a Layout Group to Rebuild 0 Answers
Anchored Positions of horizontal layout element children not set during Start Function. 1 Answer
Stretching 90° rotated RectTransform to the size of the Canvas 0 Answers
Questions about UGUI Rect Transform Anchors. How to make UI objects scale, correctly, with screen? 1 Answer