Editor View/In Game camera not positioned the same

Godot Version

4.7.2

Question

Hello,

I’ve been running into an issue where my scenes are lined up correctly within the editor like so:

In the image above, I have a player in the center (0,0) and a Camera2D that follows that player around, outside the view of the camera is a Path2D that I’m using to randomly spawn enemies from outside of the screen that will move towards the player.

However, once in game it appears as if the Path2D is actually here:

Where the red square that I’ve drawn in. Which means enemies will always spawn in the bottom right of the screen to head towards the player. When i shift the Path2D to with its bottom right corner near the center of the screen like so:

I get the desired effect with enemies spawning in correctly.

My SceneTree looks like so:

I’m going to have to assume the SceneManger (which is a root node I’m using to switch between scenes) is doing something that is offsetting everything: But given the fact that the spawner is a child of the player, and the player is positioned correctly I’m not sure why this is happening.

The only code I have in the scene manager that messes with positioning of children nodes is:

current_scene.position = get_viewport_rect().size / 2.0

Which puts the scene into the middle based on the size of the viewport.

Any help would be greatly appreciated!

Into the middle of what? If camera and everything else is parented to the player, the player will always appear in the middle of the screen.

What happens if you comment that line of code out?

Commenting out that line of code and running the game scene fixes the issue! However, doing that messes up my other scenes now:

The MainMenu now appears as if the camera starts in a position way off, with the red square the in-game view.

The blue outline of the screen boundary is hard to see but the X/Y coordinate axis in the top left should be (0,0).

I guess this might be an issue where some scenes don’t have an attached Camera2D, and other scenes do causing this issue?

The thing I’m confused about is why the CurrentScene having its position moved to the center of the viewport rect only affects certain child nodes and not all of them? If that were the case where everything is offset, I would have expected the gradient texture in the middle of the screen to also shift but that doesn’t appear to be the case.

Do my non-camera scenes need to have a centered camera to solve this issue without changing the CurrentScene position in the manager?

Adding a camera into the UI elements seems to fix this issue :slight_smile:.

I’m not sure why I thought that the UI shouldn’t have an attached Camera but that solves the issue at least for now.