Canvas Layer centering issues in editor and in final render

Version 4.3

Canvas layer centering issues in final render

I’m trying to debug why the rendered final game isn’t centered, despite everything being centered in the editor.

The above image shows one CanvasLayer that has two ColorRect’s inside of it. The larger redish transparent color and the smaller grey color. Both looks like they should be centered on the player in the editor.

However running the game produces this:

The red and grey box is rendered far to the left of the player, and I’m not entirely sure why. I know that moving the individual ColorRect nodes out of the canvas layer fixes the issue, so I have to assume this is something to do with CanvasLayers rendering differently based on some runtime configuration, I’m just unable to figure out what or why this is happening.

Moving the entire game node around the blue viewport box in the editor changes where the player renders in game with respect to the CanvasLayers, but nothing seems to ensure that they’re rendered as is shown in the editor.

I guess this might actually be closer to a question asking why the Player node I created isn’t rendering in the center of the blue viewport box shown in the editor.

Any help on the matter would be greatly appreciated!

there is no camera?

also Control nodes should use a correct anchor preset or be children of a container node. they are not Node2D, they are designed to work with multiple resolutions.

Ah, I had the camera attached to the player (to have it centered on them at all times). Should the camera be in the root game node instead of attached to the player? Additionally, why wouldn’t the player spawn in the area that it shows in the editor in the main game scene?

I’ve tried having them set underneath a Control node but I don’t see a marked difference, other tutorials and guides that I followed to achieve this affect didn’t seem to have a problem with making the render arranged like it was in the editor.

Could it also be a project settings issue? I haven’t touched my viewport settings (besides setting the height and width to some arbitrary values).

Ignore that then. I just hadn’t seen a camera in your scene.

your Controls are in a CanvasLayer, they should have their own position.

Another problem is that their are children of a Node2D.
Make the root node a Node instead so it doesn’t have position, and put the rest in a different CanvasLayer.

>Node
>	|-CanvasLayer
>	|	|-ColorRect
>	|	|-ColorRect
>	|-CanvasLayer
>	|	|-Node2D
>	|		|-Upgrades
>	|		|-Player
>	|-Timer

most godot tutorials fail on the UI part, but it’s important because it makes it so the elements can adjust to different resolutions and screen sizes.
In any case, as long as you use anchor presets it should be fine, just don’t manually edit the Controls position.

I think the default is scale, so there shouldn’t be a problem.

1 Like

Your response about the anchor presets got me thinking and I had somehow set the preset to Top Left instead of Full Rect at some point.

I have no idea what the default is supposed to be, but after putting things inside of their own layers, and then making sure the ColorRect boxes were the correct anchor preset it seems to have fixed the issue with everything rendering off-center.

Thanks again for the help!

I think the default is top-left corner.

glad I could help