Why most of my canvaslayer objects appear correctly, but one isn't?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By GameSchool


In my game, I have a scene based on Canvaslayer, that I wanted to import in a different scene (Options menu scene in the main menu scene).

The problem is, that while most of the scene appear in place, the first object in the tree appear in an incorrect location. You can see an example in the image below (Sorry about the Hebrew in the UI itself) that there is a sprite in the right corner of the screen:

What can I do about that?

Note: In my PC it appears correctly, but in some other monitors it appears like that.

Update: I checked in the editor in a pc that show the scene incorrectly, and even in the editor, when changing the offset of the Canvaslayer, the change is working on everything but the first object in the tree of the Canvaslayer scene

:bust_in_silhouette: Reply From: jgodfrey

I assume the problem is that a Sprite doesn’t inherit from Control, so it doesn’t play nicely with some of the standard control placement mechanisms (anchor, margin, …).

If your use of a Sprite is just to show a graphical element in the UI, you might be better served by a TextureRect instead. Unlike Sprite, TextureRect does inherit from Control and therefore will play nicely with other UI elements.

Thanks for the answer. Unfortunately it didn’t work, the results are the same

GameSchool | 2023-02-15 20:54

Do you see the problem when running the application on differing display resolutions? If so, I assume the problem is related to how the offending object is placed / anchored within its parent.

Can you share the layout of your scene tree (an image would be best)? Or, is the project itself available somewhere for inspection?

jgodfrey | 2023-02-15 22:14

This is how the scene looks like (canvas offset is (0, 0), but the offset set the position of all the objects, and it’s working correctly in multiple rresolutions):

enter image description here

The layout looks like that:

enter image description here

In the main scene it looks like this (Canvas offset is changed, and all the objects but the first on the scene tree apply to it). Note that in my PC changing the offset change the position of all the objects:

The tree in the main scene looks like this:

enter image description here

Update: When I entered the options menu to a completely empty scene, it worked as expected, but when I added another object to the scene tree (I tried canvaslayer, sprite2d and texturerect) is started to appear like in the example above.

GameSchool | 2023-02-16 05:32

:bust_in_silhouette: Reply From: all hail cheese

Had this exact issue. Fixed by changing renderer from Forward+ to Compatibility.
Seems like this is a bug. See: Zero child of CanvasLayer (which is a child of Camera2D) may render with wrong transform [Windows, Intel HD 630 or lower] · Issue #58314 · godotengine/godot · GitHub