Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow access to editor's Camera2D/3D #8544

Closed
p10tr3k opened this issue Nov 30, 2023 · 3 comments
Closed

Allow access to editor's Camera2D/3D #8544

p10tr3k opened this issue Nov 30, 2023 · 3 comments

Comments

@p10tr3k
Copy link

p10tr3k commented Nov 30, 2023

Describe the project you are working on

I work on project in which I read camera.zoom property to properly display my entities when I zoom out significantly.

Describe the problem or limitation you are having in your project

I would like to have the ability to do the same when I am designing the scene. Currently I have to do some ugly workarounds to achieve this. (Initial code is not mine, I found it somewhere and adapted for my purpose):

extends EditorPlugin

class_name EditorCameraHelper

const NODE_2D_VIEWPORT_CLASS_NAME = "CanvasItemEditorViewport"


var _editor_interface : EditorInterface
var _editor_viewports : Array = []
var editor_cameras : Array = []


func _init():
	_editor_interface = get_editor_interface()
	_find_viewports(_editor_interface.get_base_control())
	for v in _editor_viewports:
		_find_cameras(v)


func _find_viewports(n : Node):
	if n.get_class() == NODE_2D_VIEWPORT_CLASS_NAME:
		_editor_viewports.append(n)

	for c in n.get_children():
		_find_viewports(c)


func _find_cameras(n : Node):
	if n.get_class() == "EditorZoomWidget":
		editor_cameras.append(n)
		return

	for c in n.get_children():
		_find_cameras(c)

then in my code I can do:

func _ready():
	if Engine.is_editor_hint():
		_editor_camera_helper = EditorCameraHelper.new()
		_camera = _editor_camera_helper.editor_cameras[0]
	else:
		_camera = get_tree().get_first_node_in_group(Global.Groups.Camera)

func _process(delta):
	zoom_level = _camera.zoom if Engine.is_editor_hint() else _camera.zoom.x
	...

(currently it is not working as I want due to bug I have reported here 85524)

Describe the feature / enhancement and how it helps to overcome the problem or limitation

Provide a API to access editor's Camera.

Describe how your proposal will work, with code, pseudo-code, mock-ups, and/or diagrams

N/A

If this enhancement will not be used often, can it be worked around with a few lines of script?

N/A

Is there a reason why this should be core and not an add-on in the asset library?

N/A

@RedMser
Copy link

RedMser commented Nov 30, 2023

Why not use EditorInterface.get_editor_viewport_2d().get_camera_2d() or equivalent 3d methods? Needs Godot 4.2 btw.

@TokisanGames
Copy link

This is a duplicate of #1302 and has already been addressed by godotengine/godot#75694 and godotengine/godot#68696. The last link shows how to get all 3d editor cameras and the 2d transform.

@akien-mga

@Calinou
Copy link
Member

Calinou commented Jan 15, 2024

Closing per the above comment.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants