2

I have a canvas on the screen which for some reason is very small compared to my scene. I have a major issue placing UI components in the correct place on the canvas so that they appear in the correct place on the actual game screen.

If you take a look at the 2 attached screen grabs it may make more sense.

first image

second image

the issue I have is that when I run this on my 1080p tv the text does not get positioned correctly at all. if I place it as in the first image then it ends up 8 squares from the top and 15 squares from the right, if I place it as in the second image then it appears 12 squares from the top and 21 from the right.....

I just want the text to be near the top corner.

How do I get the edit screen and actual game to match positioning?

coolblue2000
  • 3,796
  • 10
  • 41
  • 62
  • Normally you can change the Rect Transform to position the canvas relative to the screen, but it looks like this canvas is attached to another canvas, which is weird. – Catwood Sep 25 '15 at 12:13
  • There is only 1 canvas. It was added automatically when I added the text component – coolblue2000 Sep 25 '15 at 12:15
  • Okay, the text will have some rect transform options to position it relative to the corner you want. – Catwood Sep 25 '15 at 12:16
  • Is the text rect transform relative to the canvas or the screen? As it looks like the canvas might not be placed correctly when the game is run. – coolblue2000 Sep 25 '15 at 12:20
  • To the canvas, not the screen. If its an issue with canvas position, i don't think i can help as mine always stretch to fill the screen, but i have never used the canvas scaler, so that might be the cause? – Catwood Sep 25 '15 at 12:22

3 Answers3

1

Ok, along with some pointers from Catwood above I worked out the issue. I had not set the canvas to stretch with screen!

So it was placing the text correctly it was just that the canvas was staying a fixed size rather than filling the screen.

coolblue2000
  • 3,796
  • 10
  • 41
  • 62
0

Thats exactly why you have to debug your game with your actual anticipated aspect ratio. This must be set explicitly and it can change alot about your game as the canvas can change itself drastically to accomidate.

enter image description here

maraaaaaaaa
  • 7,749
  • 2
  • 22
  • 37
0

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.

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.

user3071284
  • 6,955
  • 6
  • 43
  • 57
  • The z-axis behaves very odd when render mode is set to camera. Although this does force the canvas to fill the screen in editor mode. – coolblue2000 Sep 28 '15 at 18:59
  • The z axis has to be set above 40 in order for anything to show in the editor. However even then it does not show in the actual running game... I have to set it higher to get it showing in game.... also the components appear to be linked as if one is set below a certain zindex the others will not show...... – coolblue2000 Sep 28 '15 at 19:06
  • Sounds like you're using z depths in a 2D game with an orthographic camera (correct me if I'm wrong). It's best to keep everything at z=0 and use Sorting Layers and the Order in Layer field to configure the order they're rendered by the camera. – user3071284 Sep 28 '15 at 19:39
  • If I left the z positions at zero the ui elements would not show despite being last in the order. Everything else on the scene is at zero z position but the ui elements would not show until set to 40 or greater..... – coolblue2000 Sep 28 '15 at 20:16
  • If you ask a new question for this, let me know, and I will try to help you. – user3071284 Sep 28 '15 at 20:17
  • Ok thanks will do. I will get my project set up so that it is reproducing the issue. Then I will post a new question. – coolblue2000 Sep 28 '15 at 20:21