How to get the editor's camera?

:bust_in_silhouette: Reply From: yikescloud

I found I can manually change editor camera by this way:

func get_editor_camera(camera_index):

  var e = get_editor_interface().get_editor_viewport()
  var cam = e.get_child(1).get_child(1).get_child(0).get_child(0).get_child(cam_index).get_child(0).get_child(0).get_camera()
  return cam

If the function not work,you can use code below to check(new version godot change the camera hierarchy)

#	var root = e.get_parent()
#	var all_nodes = []
#	var c = root.get_children()
#	while !c.empty():
#		var child_list = []                        
#		for i in c:
#			child_list += i.get_children()
#		all_nodes += child_list
#		c = child_list
#	for node in all_nodes:
#		if node.get_class() == "Camera":
#			print(node.transform)
#			print(node.get_path())
#			for i in range(deep):
#				node = node.get_parent()
#				print(node.get_class() + str(node.get_index()))
#	print(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>")

I know the camera (or anything else) can be obtained by forcing some code into the scene tree of the editor, but this is not what I’m after. A solution like this is a hack that can break any moment when new versions of Godot release. I wish there was an official API for it.

Zylann | 2021-04-03 17:01

Agree. Recently I make editor plugin for my own game, I found the plugin API still lacks a lot of thing, for example it seems cannot draw something only on certain editor viewport. I hope this will get improve later.

yikescloud | 2021-04-08 06:38

Do we have API for access to the editor camera for now as it is 4.0 beta?

godotlearner | 2022-11-24 15:23