Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Voting for the Unity Awards are OPEN! We’re looking to celebrate creators across games, industry, film, and many more categories. Cast your vote now for all categories
    Dismiss Notice
  3. Dismiss Notice

Canvas same size as 2D Scene view of game: HOW?

Discussion in 'UGUI & TextMesh Pro' started by Deeeds, Mar 26, 2018.

  1. Deeeds

    Deeeds

    Joined:
    Mar 15, 2018
    Posts:
    739
    I want a UI Canvas the same exact size as my game view, in the Scene Editor, so I can position UI against the elements of the game, exactly as I'd like.

    How do I do this?

    Plopping a canvas in the project makes a canvas that's enormous. I don't want this. I just want it to exactly match my iPad game view.

    Apologies if I'm not using the right terminology. I hope you can see through any problems with terminology to the purpose.
     
  2. Sun-Dog

    Sun-Dog

    Joined:
    Mar 23, 2009
    Posts:
    144
    Don't get confused by what you see in the scene view and what you see in the game view.

    With an "overlay canvas" your UI will be stretched over the entire scene; however, it will be scaled to the size of 1 UI pixel == 1 Unity Unit, so it will appear huge in your scene.

    This will look correct in the game view.
     
  3. Deeeds

    Deeeds

    Joined:
    Mar 15, 2018
    Posts:
    739
    I have read this on several blogs, and forum posts.

    I am not concerned about this.

    What I am concerned about is my need to line up UI elements with game elements in the Scene View.

    How do I setup the canvas so I can do this?
     
    StarArcher likes this.
  4. Sun-Dog

    Sun-Dog

    Joined:
    Mar 23, 2009
    Posts:
    144
    Scene View with game:
    b07afd12a7076f60ca985e9a98dce547.png

    Note the white lines indicating the lower left corner of the UI Canvas.

    GameView & Hierarchy:
    760ec0be6bc78128e1ae1b261a3e92be.png

    SceneView in 2D Mode (note button in upper menu bar) with the Canvas in focus:
    cd367355ccbf48c23fe044f4ad6bec14.png

    Note that the UI is so large in comparison to our scene objects, we can't see it in this view.
     
    StarArcher likes this.
  5. Sun-Dog

    Sun-Dog

    Joined:
    Mar 23, 2009
    Posts:
    144
    Sorry - cross post.

    Can you give me an example of what you are trying to do?

    There are 3 canvas modes, and perhaps you need a different one, or a mix of several?
     
  6. Deeeds

    Deeeds

    Joined:
    Mar 15, 2018
    Posts:
    739
    @Sun-Dog said: "Note that the UI is so large in comparison to our scene objects, we can't see it in this view."

    I'm trying to NOT work like this, in 2D

    I'm not sure what you're missing. I want to look through my UI, directly, to my game scene, in a 2D world, where the UI canvas is the exact same size as my 2D camera's view of the scene, so I can layout my UI against the backdrop of my Scene, all at a scale where I can be exact, and use the elements of the game to position my UI.

    Eyeballing it, so to speak.
     
    StarArcher likes this.
  7. Sun-Dog

    Sun-Dog

    Joined:
    Mar 23, 2009
    Posts:
    144
    You can look at the other 2 canvas types.
    https://docs.unity3d.com/Manual/UICanvas.html (Look at Camera and World, rather than overlay)

    Perhaps I've always used my Sprite UI's in a setup like this, so I'm used to it, but I'm not sure I fully understand the reason this doesn't work for you

    Also, you can have the scene view open to move things and "eyeball it" in the game view. I usually move my UI by writing in transform values in the inspector, so I don't need the scene view all the time.

    If you give more specifics, we will be able to help you more. Are you trying to attach labels to objects (this can be done with a script and/or a different canvas mode)? Is this simply a workflow issue rather than a game-play issue?
     
    theANMATOR2b likes this.
  8. Deeeds

    Deeeds

    Joined:
    Mar 15, 2018
    Posts:
    739
    Yes, this is a workflow issue. In the scene view (not a combination of game and scene views) I want to be able to position UI elements against the positions of elements in the game... in a 2D game.

    I have an outline in the Scene View that shows the extents of the 2D camera's view.

    I want the UI Canvas to exactly match this, so I can work 1:1, UI to game elements.

    To me, it's baffling that this is not the default manner of working within a 2D game for 2D UI design within the Scene Editor.
     
    StarArcher likes this.
  9. Sun-Dog

    Sun-Dog

    Joined:
    Mar 23, 2009
    Posts:
    144
    I guess I see creating a tool that shows the extents of the camera in the scene view baffling! As this is already solved in the game view! But, hey, each to his own style, I guess.

    Try the ScreenSpace-Camera on your canvas:
    You may get this to work. I've never tried it for this use-case. It's usually used so the UI can have perspective and be set in the scene against other scene objects, but it does scale to the camera.

    After that, you could use a WorldSpace Canvas and simply set it in your scene above your game - again, I've never used it for this use-case, so your mileage may vary.

    You may be "fighting city hall" on this one, but good luck!

    Post your outcome here when you do, so other people working like you do know how to deal with it.
     
    jdivs likes this.
  10. Deeeds

    Deeeds

    Joined:
    Mar 15, 2018
    Posts:
    739
    I'm very new to Unity's GUI. This is going to take a good long while to figure out. Already been fighting City Hall, it feels like, for quite some time.

    Surely I'm not the first to want to do this...
     
    JanetEscGames likes this.
  11. gdespaux2010

    gdespaux2010

    Joined:
    Feb 16, 2017
    Posts:
    34
    I know this is almost a year old, but this was one of the top results on Google, and for someone moving from Unity 3D to 2D, it's a perfectly valid question. The answer for me was to change the Render Mode on the Canvas object to Screen Space - Camera. Then, set the Render Camera right below that to your scene camera (Main Camera, if it's default)

    Just a heads up, though, my particular game takes place entirely in the bounds of the screen (mobile game) and the camera doesn't move at all. So, I don't know how this would affect games with a moving camera. I hope this helps any future searchers.
     
  12. Acidblood

    Acidblood

    Joined:
    Sep 20, 2017
    Posts:
    1
    Is there any downside to simply working at a larger scale, i.e. Pixels Per Unit of 1 instead of the default 100?
    (Note: Aside from the obvious of having to re-scale everything)
     
  13. NMD83

    NMD83

    Joined:
    Aug 18, 2014
    Posts:
    3
    I know exactly what you are asking because I'm trying to do the same thing... I would think the pixels to units settings would be precisely what we need but it does not seem to work.

    I am able to do the inverse, by setting my world space sprites to 1:1 pixels to units but that really changes my scale alot and it's very convenient for me to be able to have a specific pixel size(120 in my case) be equal to one world unit.
     
  14. NMD83

    NMD83

    Joined:
    Aug 18, 2014
    Posts:
    3
    This works but I want to use an overlay
     
  15. sleptnation

    sleptnation

    Joined:
    Jun 15, 2020
    Posts:
    1
    I had this problem and fixed it by doing this:
    ///////////////////////////////////////////////////////////////////////////////////
    Canvas element Set to :
    Render Mode: >>> Screen Space - Camera,
    RenderCamera: >>> Main Camera (Camera)

    I then went in the Game view and Set the
    Aspect Ratio: >>> 16:9
     
    jdivs likes this.