Why in the editor the ui looks fine in size but when building the game and running it's not? - unity3d

This is a screenshot of the gameview in the editor when the game is not running.
It looks the same when running the game in the editor.
The rawimage size is set to W = 821 and H = 689
Same size of the texture render.
When running the game I'm choosing resolution 1920 x 1080 my highest resolution.
And graphics ultra.
This is a screenshot when running the game from the built file in full screen.
But the preview image not the same size on the height of the canvas in the editor it looks like it is the same height but after building and running it's not :
I want the preview image to be most to the right and cover the top and bottom edges only to keep the width as it is but when running from the built file the height and position not the same like in the editor.

if you are using UI you should configure canvas scaler correctly, I configure it as the attached image and its work right for me.
but if you are using sprites you should calculate the scale of it by code, at first calculate width and height of the screen and then width and height of sprite(with sprite renderer componetn) and calculate it.
Canvas scaler configuration

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.

How can I set Unity editor resolutions properly

I'm new to unity and to be honest , it's resolution system looks very weird to me. Hope it will make sense once I get used to it. But for now, here is my problem:
I've set resolution under "build" tab to 1920x1080 (also tried with 16:9 ratio as well) . then I imported a 1920x1080 image. but when I try to display it, borders of the image doesn't show up. Clicking on play or pausing it doesn't solve it.
(approximately 20% of the image from all directions are not shown) .
what is the reason, and how can I solve this?
edit
Screenshots - intentionally draged sprite a little down so you can see canvas' borders.
ss1 https://prnt.sc/qj0pad
ss2 https://prnt.sc/qj0pty
ss3 https://prnt.sc/qj0pzs
This is due to your canvas size.
When you drag and drop an image onto your scene, it will import it as a UI Image and create a Canvas to hold it. On the Canvas, the UI Scale Mode field of the Canvas Scaler component is by default on Constant Pixel Size. You'll want to change it to Scale With Screen Size and then put your resolution in the Reference Resolution field that appeared (which is 800x600 by default).

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?

Unity Canvas does not fill screen

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)

Image size incorrect in Unity

I have a Unity 2D project with a fixed screen size of 800x450 pixels.
I have imported a background image that is also 800x450 pixels.
When placed on the stage, the image only takes up half of the screen.
The scale of the image is set to 1,1. The Z position is 0.
Why is the image displayed too small? How can I display the image at the correct resolution?
Does this mean that I have to design all my game assets at 2x the required size? Or that I somehow have to set the scale for all imported assets at 2? What is the recommended workflow?
EDIT
I have added a screenshot of the camera settings:
I would trying making your camera orthographic, and set the size of the camera (not the transform) to be half the height that you would like it to be (225)
Also if you are looking for pixel perfect game. here is a pretty good article from Unity about how to make that work and it explains some of the camera aspect ratios and scaling
http://blogs.unity3d.com/2015/06/19/pixel-perfect-2d/