- Home /
Having a bit of trouble with Unity5's canvas
I am attempting to make a UI with the canvas, and it looks great, except I went to build the project and run it for testing, and all of the canvas objects are... out of whack - meaning: misplaced, noticeably off center, etc..
Under "Canvas", I have Render Mode set to Screen Space - Overlay
Under "Canvas Scaler": Scale with screen size, match width or height.
I don't really know what they do, I read up in the Unity docs but I didn't really comprehend it well. Anyone have experience with the canvases?
Answer by Eudaimonium · May 12, 2015 at 01:08 PM
You probably didn't correctly set all the element's anchor points.
Best way to get all the elements to be roughly the same size/position on various screen resolutions is simply to outline them with anchor points, as shown here:
Notice the small white triangles behind the blue rect control handles - just make the anchor rectangle closely fit the element's outline and you should be good to go in most cases.
Can you explain a little on how anchors work please? I am still a little confused
Oh, I got it! It took me a bit to figure out what you were trying to say.
The anchor is a rectangle that is always a fixed size on canvas - notice how when you're resizing the anchor, the values are written in a percentage of the screen size?
The element's size is the finally calculated from the anchor - the element's border is always the exact same distance to the corresponding anchor border.
That's about as best as I can roughly explain it, you have more info here: http://docs.unity3d.com/$$anonymous$$anual/HOWTO-UI$$anonymous$$ultiResolution.html
Basically, it just boils down to outlining the elements with their anchors, if you want to keep the elements the constant size across screen sizes. You can always experiment, seperate your game window from main Unity window, and as you resize that, you will notice your canvas and everything resizing along with it, and you can see in real time how it all behaves.
Your answer
Follow this Question
Related Questions
Set Native Size in UI 1 Answer
How to attach a (that world type) canvas to a moving player? 0 Answers
Scrollview Without Canvas 1 Answer
Unity 5 GUI Buttons Won't Show When Built 0 Answers
Unity 5 and Pixel-Perfect in the Canvas 0 Answers