Search Unity

Setting Custom Canvas Size

Discussion in 'UGUI & TextMesh Pro' started by Knowitall66, Aug 22, 2014.

  1. Knowitall66

    Knowitall66

    Joined:
    Oct 18, 2012
    Posts:
    4
    My apologizes in advance if this has already been answered.

    How can I manually set the canvas to a specific size?
    Or alternatively force it to make use of the standalone default resolution?

    It seems to be dependent on the game view (in editor) resolution and ignores that 'Maximize On Play' is enabled which is not helpful as it results in the canvas taking an obscure, unusable size.

    EDIT: fixed a typo
     
    Last edited: Aug 23, 2014
  2. DESTRUKTORR

    DESTRUKTORR

    Joined:
    Jul 4, 2012
    Posts:
    22
    The canvas can only take on a custom size if it is set to WorldSpace coordinates. What coordinate setting are you using?
     
  3. TheRobWatling

    TheRobWatling

    Joined:
    Feb 18, 2013
    Posts:
    45
    You can add the Reference Resolution Script and define a resolution you want.
     
    StarManta likes this.
  4. Knowitall66

    Knowitall66

    Joined:
    Oct 18, 2012
    Posts:
    4
    I'm aware that it can be done with WorldSpace, but I don't see why it should force me to do that. Rather the fact it works on the game view size (while in editor) is not logical.

    That component still works off game view size, while in editor.


    As a temporary solution I added a custom editor script that sets it to the correct size, however whenever I switched tabs it reset again, so I changed it so the script executes in editor and changes canvas size on update.
    Then I realized I was over complicating things and have the canvas set to WorldSpace, then there's a simple script that switches it to overlay mode on awake.

    If some one does know of a better solution, I would love to hear it.

    EDIT: fixed a typo
     
    Last edited: Aug 23, 2014
  5. superpig

    superpig

    Drink more water! Unity Technologies

    Joined:
    Jan 16, 2011
    Posts:
    4,659
    How do you intend the canvas to behave when your game is run at different display resolutions?
     
  6. runevision

    runevision

    Joined:
    Nov 28, 2007
    Posts:
    1,892
    Just to clarify and avoid confusion, the Canvas uses the Game View resolution, not the Scene View resolution, although in certain cases they are the same. The Game View is a representation of the entire screen, even if its resolution is not always the same as the final player or app will have. The Canvas is meant to cover the entire screen when set to Screen Space modes, hence the entire Game View when in the editor.

    If you want the Canvas to match the screen in the final player or app, change the current platform in the build settings to be the platform of choice using the Switch Platform button ( http://docs.unity3d.com/Manual/PublishingBuilds.html ), and then choose the appropriate resolution from the drop down in the upper left corner of the Game View.

    Unfortunately the Game View has a limitation that if it's physically smaller than the desired resolution, then it won't be able to represent the chosen resolution and will choose a smaller one instead. We wish to fix that problem but won't be able to do it for 4.6. However, if you add a ReferenceResolution component to the Canvas (and set its reference resolution to the desired values), the Canvas will scale down and work in a way very similar to in the final player or app.
     
    CraigyX, elvirais and Croomraider like this.
  7. Knowitall66

    Knowitall66

    Joined:
    Oct 18, 2012
    Posts:
    4
    I'm aware, it was a typo on my part. I've corrected the post.

    Indeed that's the issue I created this thread about, which I was hoping there was a solution to. So I guess I'll be waiting on a future version.
    The reason I do not wish to use the ReferenceResolution component is that if I ever alter the game views aspect ratio (in editor), it will alter the canvas size in the scene, I wish for the canvas to remain a fixed size while editing. I've also noticed the component has precision issues, I've experienced up +/- 0.7f.


    Scale appropriately.
    I think you may be misunderstanding me, while working in editor I want to have the canvas set to the standalone default resolution so I can work off a resolution I'm comfortable with (as working in normalized device co-ordinance is not an option).
     
    Last edited: Aug 23, 2014
  8. superpig

    superpig

    Drink more water! Unity Technologies

    Joined:
    Jan 16, 2011
    Posts:
    4,659
    Have you tried setting the Game View to use a fixed resolution, using the dropdown in the top left corner of the Game View?
     
  9. Knowitall66

    Knowitall66

    Joined:
    Oct 18, 2012
    Posts:
    4
    As I've stated in my previous post, I do not wish for it to be dependent on the editors game view resolution.


    In any case I'll stick to using WorldSpace to Overlay on Awake method until there's a better alternative.
     
    Last edited: Aug 23, 2014
  10. superpig

    superpig

    Drink more water! Unity Technologies

    Joined:
    Jan 16, 2011
    Posts:
    4,659
    Yes, I know. If you set the Game View to be a resolution smaller than the window size, then it will be exactly that resolution, it won't be dependent on the window size. Then you can author your UI whilst thinking in pixels, and stick a ReferenceResolution on the canvas to make it scale to different resolutions in the build.
     
  11. runevision

    runevision

    Joined:
    Nov 28, 2007
    Posts:
    1,892
    To be clear, the Game View got a new feature in Unity 5.4 to be able to zoom the view. With this feature, the Game View now correctly uses the specified resolution, rather than using a lower resolution if the specified one doesn't fit. This is what Richard "Superpig" Fine is referring to. (This isn't available if you're using Unity 5.3 or lower.)

    When I originally wrote this...
    ...this is exactly what was addressed in 5.4. :)
     
    elvirais and Harinezumi like this.
  12. hkone1

    hkone1

    Joined:
    Jun 6, 2017
    Posts:
    24

    hi superpig :), Hi, the canvas just does not change height, it always stays at 503 pixels and not 576, the canvas scales with the width but not the height, screenshot: https://drive.google.com/open?id=0B_ReTiIOnFd0bkhyWldaRktLSEU
    im just not able to fix this pls help thx!
     
  13. runevision

    runevision

    Joined:
    Nov 28, 2007
    Posts:
    1,892
    This is by design when you have the Canvas Scaler set to match width and not height. If you want to match by height instead, move the slider over to the "height" position.

    The Canvas Scaler does not support non-uniform stretching, i.e. stretching by different amounts horizontally and vertically, since it most often looks really bad. Hence it cannot match both width and height at the same time, though it can do a little of each.

    If you want to do it anyway, it would be possible to grab the source code for the Canvas Scaler component (most of the UI system is open source) and make a new version that fits your needs.
     
  14. printonline

    printonline

    Joined:
    Mar 6, 2019
    Posts:
    1
    Just to make clear and avoid confusion, the Canvas uses the Game View choice, not the Scene View resolution, although in sure cases they may be the equal. The Game View is a representation of the whole show display screen, despite the fact that its decision isn't usually similar to the very last player or app may have. The Canvas is supposed to cowl the complete display while set to Screen Space modes, consequently the whole Game View even as inside the editor. If you want the canvas prints to match the display display inside the final participant or app, trade the current platform within the assemble settings to be the platform of choice the use of the Switch Platform button ( http://medical medical doctors.Unity3d.Com/Manual/PublishingBuilds.Html ), and then pick out the correct choice from the drop down in the top left nook of the Game View. Unfortunately the Game View has a dilemma that if it's physically smaller than the favored choice, then it may not be able to constitute the chosen decision and will pick out a smaller one rather. We want to restore that trouble however might not be capable of do it for four.6. However, in case you add a ReferenceResolution difficulty to the Canvas (and set its reference decision to the preferred values), the Canvas will slash and work in a manner very similar to within the very last participant or app.

    Have you tried placing the Game View to use a fixed resolution, using the dropdown in the pinnacle left corner of the Game View?
     
  15. WheresMommy

    WheresMommy

    Joined:
    Oct 4, 2012
    Posts:
    890
    What about a second camera and put its view to a specific size, render to a rendertexture and put that in a rawimage on your maincanvas with aspectratio to your needs on the rawimage. So it will scale with only max height or width of gameview canvas?