How do I get the editor camera's position vector for a tool script?

Godot Version

4.4.stable

Question

I would like to save the editor’s camera position as a variable in a tool script. Also if anyone knows how to format such a tool script that would be great to know as well.

Edit:
More specifically I am trying to get the position of the center of the 2D editor camera in relation to the in-game area.

I guess what I’d really like is to get the numbers at the center of the top ruler bar and the center of the left ruler bar.

Add @tool at the top of the script.

As for the camera’s position, once you identify it as an object, say you call iteditor_camera you would just write editor_camera.position or editor_camera.global_position.

1 Like

Which camera? In 2D or 3D?

You can get the SubViewport of the editor’s 2D or 3D views with EditorInterface.get_editor_viewport_2d() and EditorInterface.get_editor_viewport_3d() The documentation of those functions tells you how to get the camera in both cases.

2 Likes

I am trying to get the position of the center of the 2D editor camera in relation to the in-game area.

I guess what I’d really like is to get the numbers at the center of the top ruler bar and the center of the left ruler bar