Unity Canvas does not fill screen - unity3d

I have a 2D game set to 1080p pixel size (so each unit equals 1 pixel) and I have added a canvas to my scene. However the canvas fills only about 1/8th of the screen and is also not central either. All the canvas size and position settings are locked so I cant move it or resize it. The canvas itself does reflect the screen (ie if I put text in the top right corner it appears correctly) but the size makes it hard to judge where best to position the elements).
How do I get the canvas to fill my scene?

On your canvas, set the Canvas Scaler component's Ui Scale Mode to Scale with Screen Size. Then you can define a Reference Resolution of 1080p, i.e. 1920 x 1080.
EDIT: To see the canvas fit into the camera's size in the scene, change the Canvas component's Render Mode to Screen Space - Camera, and drag the camera from the hierarchy to it.
(check this video)

Related

Camera wrong orientation?

I created an empty 2D project - to try a tutorial from here
https://codeplanstudio.com/tutorials/block-adventure-game-tutorial/
(episode 2).
Added assets (graphics)
created Canvas
in the Canvas
a. canvas rendering mode Screen Space Camera
b. rendering camera set to Main Camera
c. Canvas scaler: scale with screen size, Reference resolution set x:1920 y:1080, match 0.5
added UI image to Canvas
in image
a. source image - an image from assets
b. set native size (native size is width:1080 height:1920)
When I look at the scene, the camera has the same dimensions with the canvas, but inverted: what should have been height is width and what should have been width is height.
What I was expecting was this (as seen in a video tutorial):
Any suggestions?
In your GameView on the top bar there is the Display X dropdown and right next to it a resolution dropdown.
Per default it is usually Free Aspect which means the camera resolution is whatever the resolution of the GameView window is.
Open the dropdown and click on + to create a new resolution option
Adjust it according to you needs e.g.
or using a dynamic resolution but fixed aspect ratio.
Now you can select it and no matter how the GameView window is scaled now it always keeps this fixed resolution (or aspect ratio) for the camera.

Unity UI with different screen sizes

I am making a game and have a problem with UI. I made it to scale with the screen size. In 16:9 it looks as I want to:
UI is where I want it to be.
But when I switch to 2160 x 1080 I have a problem.
My UI is outside my game screen
I want that my UI on 18:9 stays in the same position as in 16:9. Any solutions to make it stay inside game bounds?
Canvas object -> Canvas Scaler component:
Scale With Screen Size
Match = 0 (0 for vertical app, 1 for landscape)
And then you need to change anchors for ui objects to align not from borders, but from center.
If you want UI to cover entire page make sure you hold shif + alt and select the stretch preset Unity will always cover the entire screen irrespective to resolution
Unity anchor preset
refrence

Canvas too big for the camera in Unity

I have created a 2D game with an orthogonal camera and using 16:9 display size.
I dragged my background image onto the hierarchy (it's about 2048x1152) and then set the camera size to be 22.5, which made it fit the background perfectly and displays just right.
However, when I add a Canvas for a UI it is absolutely giant, about 100 times bigger. It only becomes 'normal' size with respect everything else added when I set the camera to its default size of 5. So when I add a small graphic, it too becomes giant.
I'm simply following a book I read and I'm not doing anything to deviate.
Am I doing something wrong? Below is what I mean. The background image is the little image in the bottom right and the outlined rectangle is the canvas with a small graphic added.
Thanks.
To force your Hierarchy Canvas UI to the same resolution as the Camera View in your Unity Editor Scene window resolution (i.e. not ridiculously massive), or in other words get the Canvas to fit into the Camera size in the Scene, do the following:
Set the Canvas component's Render Mode to Screen Space - Camera.
Make sure you select or drag the relevant Camera from the Hierarchy to the Render Camera field in the Inspector.
You should use the Unity canvas for this along with the canvas scaler component. If I'm not mistaken it will scale all elements relative to the screen they are viewed on.
The canvas scaler allows you to match the scaling based on a preferred viewport size which is a life saver.
However this may not fit you needs perfectly as it would mean that the background element would become fixed. So if you wanted to pan the element you would need to move it's x and y elements within the canvas.
Hope that helps?

Match Canvas with Main Camera - Unity

I want to use the Canvas and UI Text to constantly show the score of my game on the top right corner of the screen. How can I initialize the Canvas so that its position and dimensions perfectly match the border of the camera? (2D Setup)
To see the canvas fit into the camera's size in the scene, change the Canvas component's Render Mode to Screen Space - Camera, and drag the camera from the hierarchy to it.

aabb.IsValid() Error with Canvas Scaler and Sprites (Unity3d)

I am trying to add a sprite background to my canvas.
The canvas is set to render mode Screen Space- Camera so that the canvas size matches the main camera view.
The canvas scaler is set to scale with screen size with a reference resolution of 1920 x 1080.
When I place any sprite into the canvas as a child I get errors that occurs only when unity first starts.
aabb.IsValid()
IsFinite(outDistanceForSort)
UnityEditor.DockArea:OnGUI()
IsFinite(outDistanceAlongView)
UnityEditor.DockArea:OnGUI()
I am thinking this is a bug just with the scene/game previewer in unity itself since when I clear the error on initial load it does not come back. I know it has to do with either the canvas scaler or the sprites since when I disable them either of them the error does not appear. Also, I need the settings to scale as I have them set so that the background images are properly sized in different resolutions.