I have a few questions regarding the UI, which I havnt been able to find answers to.
I wanted to use the canvas setting screen space - overlay, however if I strech my UI elements to fill the whole canvas rectangle, it doesnt match the screen size in the game view. Everything is pushed a bit to the right. Is there an extra step in order to match the camera view with the screen space - overlay?
As far as I understood you have to use screen coordinates when placing UI elements in screen space - overlay mode and you have to use world coordinates when placing elements in screen space - camera mode.
I noticed however that when changing the position (in script) of an UI element in screen space - camera mode and then assigning the canvas as a parent, makes the element position relative to the anchors of the UI element. However when assigning the canvas as a parent before the position is changed, everything is good (positions are world space). Is this normal behaviour?
I just found the problem, my canvas was a child of another object which didnt have its center in (0,0,0). Placing the parent object in 0 fixed the issue for screen space - overlay.
Im still trying to figure out which coordinate systems to use when assigning object positions through script for the different screen spaces. What is the recommended way?
Should you use screen coordinates when using screen space - overlay and world space coordinates when using screen space - camera?
I noticed that when using localposition in both modes, it seems to be using the screen coordinates?
I’ve got the same problem. While I thought that screenspace ui should be always aligned to the screen, when I place the canvas as a child of a regular GameObject, its worldspace transform.position affects canvas position. As a rule of thumb I decided to never set the screenspace canvas as a child of worldspace object, but wandering is it intended behaviour
That seems to be the case, maybe it’s just a design choice. Not very logical on surface as that’s it’s supposed to be “screen space” :), but it can be also useful, as canvas can be transformed.
As you said it doesn’t matter if you parent RectTransform with Canvas component to GameObject with Transform or RectTransform, moving it moves ScreenSpace Canvas that is child of this object.
However, setting Canvas to ScreenSpace Camera + assigning a camera seems to counter this - then moving parent of canvas doesn’t allow Canvas to move along with it. Haven’t tested this practice, but that’s how it behaves in editor.