- Home /
Content Size Fitter and Anchors / UI Scaling?
Hi All,
I'm creating a complex GUI using the new uGUI in Unity4.6, but I have a question about the Content Size Fitter component.
I've been using Horizontal/Vertical Layout Group components, Layout Element components, and Content Size Fitter components to get the GUI just right, but I have a problem with UI scaling across various screen aspects.
What I'd like to have is a GUI that is proportionally the same across all screen aspects and resolutions. That is, I want the GUI to occupy the same percentage of the screen area no matter what the aspect or the resolution.
To accomplish this in uGUI, I usually just ensure that the anchors of the object are set to the four corners of the object. Unity then magically takes care of the scaling for me when things are setup this way.
... UNLESS, you have a Content Size Fitter component. When you have a Content Size Fitter, it looks like Unity just ignores the anchors and doesn't scale like I expect.
Here is an example from my Unity IDE. This is the 16x9 aspect. Everthing is great. The panel with the Content Size Fitter takes up the entire vertical space of the screen as I want.
This is the 5x4 aspect. The panel on the left scaled correctly, but the panel on the right with the Content Size Fitter didn't scale. It is now smaller than the vertical size of the screen.
Is there something I can do about this?
I really want to have a UI that scales and I really want to use the Content Size Fitter to help with layout. Can I do this?
If not, is there another approach here that I'm really supposed to be using ...
Any help would be appreciated.
Where do you want to use the ContentSizeFitter for? Since I believe this is expected behaviour...
Since this component controls the height (or width) based on Layout (Which in turn is based on its content like the: 'Text Component', 'Layout Element', etc.) so what you basically do if you add a ContentSizeFitter is that you overwrite the height (or in your case 'H delta') value of your RectTransform.
But in your setup there is no point in doing that since you want that value to be 0...
Answer by Freezy · Jan 19, 2015 at 09:03 PM
give this a try https://github.com/FreezyExp/uGUI-SizePerChild
Answer by krstrobe · Aug 16, 2016 at 05:04 PM
I think you might want to go to your main canvas, go to the canvas scaler component and set it to "Scale with screen size." Then play around with the match. for me I have to set it to 1 (all the way to the right).
Your answer
Follow this Question
Related Questions
IPointerClickHandler error 2 Answers
Remove Focus From InputField 2 Answers
Text blurred: uGUI 4.6 9 Answers
Set Animation curve for uGUI elements 0 Answers
ugui 4.6 Slider automatic reset 2 Answers