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).
Related
First of all, sry for my English mistakes, I'm not a native English speaker.
I'm trying to make an UI which is composed of a canvas within different gameObject, and I would like that my canvas scales to the dimension of the screen but keeps its original resolution (16x9 portrait). If it is displayed on a tablet resolution (4x3) then an image is displayed in the space that is not covered by the canvas.
But actually all I've got is a canvas which scales to every resolution, and it changes the aspect of its child (for example a square becomes a rectangle).
Thank you for showing interest in my query!
UI's are heavy beasts. Canvas in Unity have a component attached to themm called Canvas Scaler which is set by default on Constant Pixel Size. You may try to set this property on Scale With Screen Size and then specify the base resolution you want to work with (usually 1920x1080 is a console standart). This is your first step
Then, to avoid strange Image scaling, you may check the property Preserve Aspect, this way the ration of the Sprite into your Image will remain the same indepently of the ratio of the Image
Last, you may play a bit with anchors but this is another story, you should let those at plain center at the beginning and come back to it when you will feel ready
Hope that helped ;)
Your canvas should have a component called Canvas Scaler. Here it should say Constant Pixel Size, change this to Scale With Screen Size and it should lock the Canvas to be the same width / height as the screen. If you want to lock an image to a specific width/height ratio, go to the Image component on the image and check the Preserve Aspect checkbox. This way if you have a 100x100 image, the images width will always be the same as the height. If you have a 200x100 image, the images width will always be twice the height, etc etc etc.
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.
I'm a newbie to Unity and am learning. I've made my first game which is a simple platformer, along with a main menu. The game also has some text GUI elements. When I run it in Unity's built-in player, the GUI looks fine, but when I build the project and run the game using the .exe, the UI is scaled down.
I'm attaching some screenshots below to clarify this.
(As seen in Unity player)
(As seen in game)
Also, the game UI also looks scaled down:
(As seen in player)
(As seen in game)
I want the in-game UI to be exactly like the one seen in the Unity player.
How do I fix this?
The Canvas can be set to scale with different settings if you want it to be accurate you should choose:
-Scale With Screen Size
Using the Scale With Screen Size mode, positions and sizes can be specified according to the pixels of a specified reference resolution. If the current screen resolution is larger than the reference resolution, the Canvas will keep having only the resolution of the reference resolution, but will scale up in order to fit the screen. If the current screen resolution is smaller than the reference resolution, the Canvas will similarly be scaled down to fit.
1- Go to your Canvas and select the Scale With Screen Size option
2- After that, make sure that the Reference Resolution is the same as the Game Window resolution in your Unity layout, I leave here an example:
As you can see, the resolution set on my Game window is (1024x768) and the reference resolution of the Canvas too.
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?
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/