I’ve started running into an issue with my games where I’ll implement a scene manager that has a basic node setup like so:
On game start, and on various other level change signals, the CurrentScene deletes all its child nodes, and populates it with a new scene, the logic of which works fine.
For some reason though, different scenes all center on the screen in weird ways, which I guess can be remedied by manually setting the center of the CurrentScene node to the middle of the viewport screen, but the bigger issue is certain scenes the entire layout appears to change.
And for what it is worth, running the currently selected screen (instead of using the SceneManager to get to this scene) seems to render everything fine.
Is there a specific project setting, or a node layout tree I should be using to make sure that layouts don’t randomly move about the screen when the scene changes, or do I need to manually set the camera location for every scene. My understanding was that the blue rectangle that denoted the viewport would be constant throughout the project, but it seems to not be the case here.
I do not, what does a canvas layer do that a root control node doesn’t do? Does it provide the engine with the knowledge on how to render its child control nodes?
If your control node scene is added as a child of a Node2D it will have terrible, usually top-left anchors. The Control node child sets it’s bounds to the Node2D parent, which if it’s only a Node2D it will be 0 pixels, a Control node as a child of a Sprite2D could be used to match the sprite’s size.
I’ve never made my own “scene manager” node, Godot’s own get_tree() and it’s .current_scene has worked well enough for all of my projects. I think the most accurate move is to make both your SceneManager and CurrentScene a “Node” type. As that’s how Godot’s built in Scenetree manages it.
Yes a CanvasLayer breaks the transformation inheritance, you can have it as a parent of the UI and a child of Node2Ds without the UI inheriting the Node2D’s position and strange bounds.