Unity Scaling for all Aspect Ratios for all Android mobile devices











up vote
0
down vote

favorite












I am new to Unity and I have this "issue".



I am trying to make a simple 2D mobile game (Android for now) that will be in portrait mode always but I don't manage to have the same result in all different screen sizes.



The problem is when I am trying to have the screen scaled equally in all different screen sizes, but what I get is the background cutoff either on top-bottom or left-right (I know that has to do with the Match Width Or Height) when I am trying to change screen size.



So what I am using in Canvas Scaler: Scale With Screen Size with Reference Resolution X:1080 Y:1920 and a background image of size 1080x1920.



When I try to resize to larger screen resolution (for example 1080 x 2160):




  • using Shrink the background is cutoff


  • using Expand I get "black bars".


  • using Match Width Or Height with Match: 1, I get "black bars" or Match: 0, the background is cutoff on the sides.



OR also when resizing to smaller ratio (3:4) I get either black bars or background cutoff on the sides.



All of the 16:9 (576x1024, 720x1280, 1080x1920, 1440x2560, etc) seems to be correct.



So my question is, in which way I can support all different mobile screen sizes including all different aspect ratios without getting my background cutoff or getting the black bars on the sides?



Thanks in advance.










share|improve this question


























    up vote
    0
    down vote

    favorite












    I am new to Unity and I have this "issue".



    I am trying to make a simple 2D mobile game (Android for now) that will be in portrait mode always but I don't manage to have the same result in all different screen sizes.



    The problem is when I am trying to have the screen scaled equally in all different screen sizes, but what I get is the background cutoff either on top-bottom or left-right (I know that has to do with the Match Width Or Height) when I am trying to change screen size.



    So what I am using in Canvas Scaler: Scale With Screen Size with Reference Resolution X:1080 Y:1920 and a background image of size 1080x1920.



    When I try to resize to larger screen resolution (for example 1080 x 2160):




    • using Shrink the background is cutoff


    • using Expand I get "black bars".


    • using Match Width Or Height with Match: 1, I get "black bars" or Match: 0, the background is cutoff on the sides.



    OR also when resizing to smaller ratio (3:4) I get either black bars or background cutoff on the sides.



    All of the 16:9 (576x1024, 720x1280, 1080x1920, 1440x2560, etc) seems to be correct.



    So my question is, in which way I can support all different mobile screen sizes including all different aspect ratios without getting my background cutoff or getting the black bars on the sides?



    Thanks in advance.










    share|improve this question
























      up vote
      0
      down vote

      favorite









      up vote
      0
      down vote

      favorite











      I am new to Unity and I have this "issue".



      I am trying to make a simple 2D mobile game (Android for now) that will be in portrait mode always but I don't manage to have the same result in all different screen sizes.



      The problem is when I am trying to have the screen scaled equally in all different screen sizes, but what I get is the background cutoff either on top-bottom or left-right (I know that has to do with the Match Width Or Height) when I am trying to change screen size.



      So what I am using in Canvas Scaler: Scale With Screen Size with Reference Resolution X:1080 Y:1920 and a background image of size 1080x1920.



      When I try to resize to larger screen resolution (for example 1080 x 2160):




      • using Shrink the background is cutoff


      • using Expand I get "black bars".


      • using Match Width Or Height with Match: 1, I get "black bars" or Match: 0, the background is cutoff on the sides.



      OR also when resizing to smaller ratio (3:4) I get either black bars or background cutoff on the sides.



      All of the 16:9 (576x1024, 720x1280, 1080x1920, 1440x2560, etc) seems to be correct.



      So my question is, in which way I can support all different mobile screen sizes including all different aspect ratios without getting my background cutoff or getting the black bars on the sides?



      Thanks in advance.










      share|improve this question













      I am new to Unity and I have this "issue".



      I am trying to make a simple 2D mobile game (Android for now) that will be in portrait mode always but I don't manage to have the same result in all different screen sizes.



      The problem is when I am trying to have the screen scaled equally in all different screen sizes, but what I get is the background cutoff either on top-bottom or left-right (I know that has to do with the Match Width Or Height) when I am trying to change screen size.



      So what I am using in Canvas Scaler: Scale With Screen Size with Reference Resolution X:1080 Y:1920 and a background image of size 1080x1920.



      When I try to resize to larger screen resolution (for example 1080 x 2160):




      • using Shrink the background is cutoff


      • using Expand I get "black bars".


      • using Match Width Or Height with Match: 1, I get "black bars" or Match: 0, the background is cutoff on the sides.



      OR also when resizing to smaller ratio (3:4) I get either black bars or background cutoff on the sides.



      All of the 16:9 (576x1024, 720x1280, 1080x1920, 1440x2560, etc) seems to be correct.



      So my question is, in which way I can support all different mobile screen sizes including all different aspect ratios without getting my background cutoff or getting the black bars on the sides?



      Thanks in advance.







      c# android unity3d scaling






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Nov 20 at 10:14









      Johny

      350116




      350116
























          2 Answers
          2






          active

          oldest

          votes

















          up vote
          1
          down vote













          The black bars/cutting off of your image is caused by the fact that the image is trying to preserve its aspect ratio due to using aspect ratio fitter.



          It works fine on 576x1024, 720x1280, 1440x2560 etc because the aspect ratio is the same as the original image (or canvas, which is 1080x1920) being a 9:16 aspect ratio.



          If you do not want to get either black bars or a part of the image being cut off you need to stretch/crop the image to the new aspect ratio (for example aspect ratio of 1:2 if you want 1080x2160)



          To be able to do this you need to remove the aspect ratio fitter, and make sure preserve aspect is ticked off on your image component. And then make the image always fill the canvas/screen size. E.g make a GameObject background as child of your canvas, add image component to background and set the width and height of the transform to be the same as Screen.currentResolution (from Screen class)



          This will however stretch your image out into the direction where it doesn't fit the aspect ratio (if your original image is 9:16 (1080x1920) and you want it to display 2:1 (2160x1920) it will stretch to twice it size on the x axis, resulting in a warped, and mostly ugly image). To counter this you will probably want to make seperate images for non standard aspect ratios, or make an image that doesn't look bad when stretched.






          share|improve this answer





















          • Thank you for the detailed answer! It helped me understand more about aspect ratio. I had already tried to use 1080x2160 but still in different aspect ratios there were again black bars and cutoffs. Can you explain the last part you said "To counter this you will probably want to make seperate images for non standard aspect ratios, or make an image that doesn't look bad when stretched."
            – Johny
            Nov 20 at 12:50




















          up vote
          1
          down vote













          The problem is that your canvas scaler does scale to the screen size, but your background does not. The size of the background image is fixed to 1080x1920.



          I think the easiest way to do this scale (stretch) is to set the image to fill the parent (the canvas object).



          To achieve this, you can set the anchor of the background image to these values. Like this Post.



          Anchors

          Min X 0 Y 0

          Max X 1 Y 1


          Or just use the anchor preset to set these values.



          You can get more info about the anchors from here.



          But like @remy_rm said, this approach will stretch your background image.






          share|improve this answer





















          • Your answer helped me to improve my results by using Anchors Min 0,0 and Max 1,1. Now indeed the background is stretched without getting black bars or cutoffs. Thank you.
            – Johny
            Nov 20 at 12:55











          Your Answer






          StackExchange.ifUsing("editor", function () {
          StackExchange.using("externalEditor", function () {
          StackExchange.using("snippets", function () {
          StackExchange.snippets.init();
          });
          });
          }, "code-snippets");

          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "1"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53390730%2funity-scaling-for-all-aspect-ratios-for-all-android-mobile-devices%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          2 Answers
          2






          active

          oldest

          votes








          2 Answers
          2






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes








          up vote
          1
          down vote













          The black bars/cutting off of your image is caused by the fact that the image is trying to preserve its aspect ratio due to using aspect ratio fitter.



          It works fine on 576x1024, 720x1280, 1440x2560 etc because the aspect ratio is the same as the original image (or canvas, which is 1080x1920) being a 9:16 aspect ratio.



          If you do not want to get either black bars or a part of the image being cut off you need to stretch/crop the image to the new aspect ratio (for example aspect ratio of 1:2 if you want 1080x2160)



          To be able to do this you need to remove the aspect ratio fitter, and make sure preserve aspect is ticked off on your image component. And then make the image always fill the canvas/screen size. E.g make a GameObject background as child of your canvas, add image component to background and set the width and height of the transform to be the same as Screen.currentResolution (from Screen class)



          This will however stretch your image out into the direction where it doesn't fit the aspect ratio (if your original image is 9:16 (1080x1920) and you want it to display 2:1 (2160x1920) it will stretch to twice it size on the x axis, resulting in a warped, and mostly ugly image). To counter this you will probably want to make seperate images for non standard aspect ratios, or make an image that doesn't look bad when stretched.






          share|improve this answer





















          • Thank you for the detailed answer! It helped me understand more about aspect ratio. I had already tried to use 1080x2160 but still in different aspect ratios there were again black bars and cutoffs. Can you explain the last part you said "To counter this you will probably want to make seperate images for non standard aspect ratios, or make an image that doesn't look bad when stretched."
            – Johny
            Nov 20 at 12:50

















          up vote
          1
          down vote













          The black bars/cutting off of your image is caused by the fact that the image is trying to preserve its aspect ratio due to using aspect ratio fitter.



          It works fine on 576x1024, 720x1280, 1440x2560 etc because the aspect ratio is the same as the original image (or canvas, which is 1080x1920) being a 9:16 aspect ratio.



          If you do not want to get either black bars or a part of the image being cut off you need to stretch/crop the image to the new aspect ratio (for example aspect ratio of 1:2 if you want 1080x2160)



          To be able to do this you need to remove the aspect ratio fitter, and make sure preserve aspect is ticked off on your image component. And then make the image always fill the canvas/screen size. E.g make a GameObject background as child of your canvas, add image component to background and set the width and height of the transform to be the same as Screen.currentResolution (from Screen class)



          This will however stretch your image out into the direction where it doesn't fit the aspect ratio (if your original image is 9:16 (1080x1920) and you want it to display 2:1 (2160x1920) it will stretch to twice it size on the x axis, resulting in a warped, and mostly ugly image). To counter this you will probably want to make seperate images for non standard aspect ratios, or make an image that doesn't look bad when stretched.






          share|improve this answer





















          • Thank you for the detailed answer! It helped me understand more about aspect ratio. I had already tried to use 1080x2160 but still in different aspect ratios there were again black bars and cutoffs. Can you explain the last part you said "To counter this you will probably want to make seperate images for non standard aspect ratios, or make an image that doesn't look bad when stretched."
            – Johny
            Nov 20 at 12:50















          up vote
          1
          down vote










          up vote
          1
          down vote









          The black bars/cutting off of your image is caused by the fact that the image is trying to preserve its aspect ratio due to using aspect ratio fitter.



          It works fine on 576x1024, 720x1280, 1440x2560 etc because the aspect ratio is the same as the original image (or canvas, which is 1080x1920) being a 9:16 aspect ratio.



          If you do not want to get either black bars or a part of the image being cut off you need to stretch/crop the image to the new aspect ratio (for example aspect ratio of 1:2 if you want 1080x2160)



          To be able to do this you need to remove the aspect ratio fitter, and make sure preserve aspect is ticked off on your image component. And then make the image always fill the canvas/screen size. E.g make a GameObject background as child of your canvas, add image component to background and set the width and height of the transform to be the same as Screen.currentResolution (from Screen class)



          This will however stretch your image out into the direction where it doesn't fit the aspect ratio (if your original image is 9:16 (1080x1920) and you want it to display 2:1 (2160x1920) it will stretch to twice it size on the x axis, resulting in a warped, and mostly ugly image). To counter this you will probably want to make seperate images for non standard aspect ratios, or make an image that doesn't look bad when stretched.






          share|improve this answer












          The black bars/cutting off of your image is caused by the fact that the image is trying to preserve its aspect ratio due to using aspect ratio fitter.



          It works fine on 576x1024, 720x1280, 1440x2560 etc because the aspect ratio is the same as the original image (or canvas, which is 1080x1920) being a 9:16 aspect ratio.



          If you do not want to get either black bars or a part of the image being cut off you need to stretch/crop the image to the new aspect ratio (for example aspect ratio of 1:2 if you want 1080x2160)



          To be able to do this you need to remove the aspect ratio fitter, and make sure preserve aspect is ticked off on your image component. And then make the image always fill the canvas/screen size. E.g make a GameObject background as child of your canvas, add image component to background and set the width and height of the transform to be the same as Screen.currentResolution (from Screen class)



          This will however stretch your image out into the direction where it doesn't fit the aspect ratio (if your original image is 9:16 (1080x1920) and you want it to display 2:1 (2160x1920) it will stretch to twice it size on the x axis, resulting in a warped, and mostly ugly image). To counter this you will probably want to make seperate images for non standard aspect ratios, or make an image that doesn't look bad when stretched.







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Nov 20 at 10:56









          remy_rm

          611114




          611114












          • Thank you for the detailed answer! It helped me understand more about aspect ratio. I had already tried to use 1080x2160 but still in different aspect ratios there were again black bars and cutoffs. Can you explain the last part you said "To counter this you will probably want to make seperate images for non standard aspect ratios, or make an image that doesn't look bad when stretched."
            – Johny
            Nov 20 at 12:50




















          • Thank you for the detailed answer! It helped me understand more about aspect ratio. I had already tried to use 1080x2160 but still in different aspect ratios there were again black bars and cutoffs. Can you explain the last part you said "To counter this you will probably want to make seperate images for non standard aspect ratios, or make an image that doesn't look bad when stretched."
            – Johny
            Nov 20 at 12:50


















          Thank you for the detailed answer! It helped me understand more about aspect ratio. I had already tried to use 1080x2160 but still in different aspect ratios there were again black bars and cutoffs. Can you explain the last part you said "To counter this you will probably want to make seperate images for non standard aspect ratios, or make an image that doesn't look bad when stretched."
          – Johny
          Nov 20 at 12:50






          Thank you for the detailed answer! It helped me understand more about aspect ratio. I had already tried to use 1080x2160 but still in different aspect ratios there were again black bars and cutoffs. Can you explain the last part you said "To counter this you will probably want to make seperate images for non standard aspect ratios, or make an image that doesn't look bad when stretched."
          – Johny
          Nov 20 at 12:50














          up vote
          1
          down vote













          The problem is that your canvas scaler does scale to the screen size, but your background does not. The size of the background image is fixed to 1080x1920.



          I think the easiest way to do this scale (stretch) is to set the image to fill the parent (the canvas object).



          To achieve this, you can set the anchor of the background image to these values. Like this Post.



          Anchors

          Min X 0 Y 0

          Max X 1 Y 1


          Or just use the anchor preset to set these values.



          You can get more info about the anchors from here.



          But like @remy_rm said, this approach will stretch your background image.






          share|improve this answer





















          • Your answer helped me to improve my results by using Anchors Min 0,0 and Max 1,1. Now indeed the background is stretched without getting black bars or cutoffs. Thank you.
            – Johny
            Nov 20 at 12:55















          up vote
          1
          down vote













          The problem is that your canvas scaler does scale to the screen size, but your background does not. The size of the background image is fixed to 1080x1920.



          I think the easiest way to do this scale (stretch) is to set the image to fill the parent (the canvas object).



          To achieve this, you can set the anchor of the background image to these values. Like this Post.



          Anchors

          Min X 0 Y 0

          Max X 1 Y 1


          Or just use the anchor preset to set these values.



          You can get more info about the anchors from here.



          But like @remy_rm said, this approach will stretch your background image.






          share|improve this answer





















          • Your answer helped me to improve my results by using Anchors Min 0,0 and Max 1,1. Now indeed the background is stretched without getting black bars or cutoffs. Thank you.
            – Johny
            Nov 20 at 12:55













          up vote
          1
          down vote










          up vote
          1
          down vote









          The problem is that your canvas scaler does scale to the screen size, but your background does not. The size of the background image is fixed to 1080x1920.



          I think the easiest way to do this scale (stretch) is to set the image to fill the parent (the canvas object).



          To achieve this, you can set the anchor of the background image to these values. Like this Post.



          Anchors

          Min X 0 Y 0

          Max X 1 Y 1


          Or just use the anchor preset to set these values.



          You can get more info about the anchors from here.



          But like @remy_rm said, this approach will stretch your background image.






          share|improve this answer












          The problem is that your canvas scaler does scale to the screen size, but your background does not. The size of the background image is fixed to 1080x1920.



          I think the easiest way to do this scale (stretch) is to set the image to fill the parent (the canvas object).



          To achieve this, you can set the anchor of the background image to these values. Like this Post.



          Anchors

          Min X 0 Y 0

          Max X 1 Y 1


          Or just use the anchor preset to set these values.



          You can get more info about the anchors from here.



          But like @remy_rm said, this approach will stretch your background image.







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Nov 20 at 11:24









          ming060

          12715




          12715












          • Your answer helped me to improve my results by using Anchors Min 0,0 and Max 1,1. Now indeed the background is stretched without getting black bars or cutoffs. Thank you.
            – Johny
            Nov 20 at 12:55


















          • Your answer helped me to improve my results by using Anchors Min 0,0 and Max 1,1. Now indeed the background is stretched without getting black bars or cutoffs. Thank you.
            – Johny
            Nov 20 at 12:55
















          Your answer helped me to improve my results by using Anchors Min 0,0 and Max 1,1. Now indeed the background is stretched without getting black bars or cutoffs. Thank you.
          – Johny
          Nov 20 at 12:55




          Your answer helped me to improve my results by using Anchors Min 0,0 and Max 1,1. Now indeed the background is stretched without getting black bars or cutoffs. Thank you.
          – Johny
          Nov 20 at 12:55


















          draft saved

          draft discarded




















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.





          Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


          Please pay close attention to the following guidance:


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53390730%2funity-scaling-for-all-aspect-ratios-for-all-android-mobile-devices%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          404 Error Contact Form 7 ajax form submitting

          How to know if a Active Directory user can login interactively

          TypeError: fit_transform() missing 1 required positional argument: 'X'