Godot Version
v4.2.1.stable.official [b09f793f5]
Question
Hello, I have a plugin that can move its editor panel between different sections of the Godot editor, when it does this it appears in the console:
scene/main/canvas_item.cpp:1052 - Parameter "get_viewport()" is null.
scene/main/viewport.cpp:3390 - Condition "!is_inside_tree()" is true.
I tried to understand what is happening, to explain it I must first mention the method:
func _move_to(index):
if place in [PLACE_TOOLBAR, PLACE_SPATIAL_EDITOR_MENU]:
popup.hide()
var file = FileAccess.open(PLACE, FileAccess.WRITE)
file.store_string(str(index))
file.close()
_remove_panel()
_add_panel()
This code is located in the main code of my plugin (the same plugin script), and it is being called correctly when it needs to be transferred somewhere else. Through a bit of trial and error, I figured out that the issue is in _remove_panel()
. (As can be guessed from the errors) This function is responsible for removing the panel; all the variables used (including the panel, button, and popup specified in _enter_tree()
) are set, and the problem must stem from one (or two) of them:
func _remove_panel():
move_list.item_selected.disconnect(self._move_to)
match place:
PLACE_BOTTOM:
remove_control_from_bottom_panel(panel)
PLACE_TOOLBAR:
remove_control_from_container(EditorPlugin.CONTAINER_TOOLBAR, button)
EditorInterface.get_base_control().remove_child(popup)
button.pressed.disconnect(self._show_popup)
PLACE_SPATIAL_EDITOR_MENU:
remove_control_from_container(EditorPlugin.CONTAINER_SPATIAL_EDITOR_MENU, button)
EditorInterface.get_base_control().remove_child(popup)
button.pressed.disconnect(self._show_popup)
PLACE_SPATIAL_EDITOR_SIDE_LEFT:
remove_control_from_container(EditorPlugin.CONTAINER_SPATIAL_EDITOR_SIDE_LEFT, panel)
PLACE_SPATIAL_EDITOR_SIDE_RIGHT:
remove_control_from_container(EditorPlugin.CONTAINER_SPATIAL_EDITOR_SIDE_RIGHT, panel)
PLACE_SPATIAL_EDITOR_BOTTOM:
remove_control_from_container(EditorPlugin.CONTAINER_SPATIAL_EDITOR_BOTTOM, panel)
PLACE_CANVAS_EDITOR_MENU:
EditorInterface.get_base_control().remove_child(popup)
remove_control_from_container(EditorPlugin.CONTAINER_CANVAS_EDITOR_MENU, button)
button.pressed.disconnect(self._show_popup)
PLACE_CANVAS_EDITOR_SIDE_LEFT:
remove_control_from_container(EditorPlugin.CONTAINER_CANVAS_EDITOR_SIDE_LEFT, panel)
PLACE_CANVAS_EDITOR_SIDE_RIGHT:
remove_control_from_container(EditorPlugin.CONTAINER_CANVAS_EDITOR_SIDE_RIGHT, panel)
PLACE_CANVAS_EDITOR_BOTTOM:
remove_control_from_container(EditorPlugin.CONTAINER_CANVAS_EDITOR_BOTTOM, panel)
PLACE_INSPECTOR:
remove_control_from_container(EditorPlugin.CONTAINER_INSPECTOR_BOTTOM, panel)
_:
remove_control_from_docks(panel)
What strikes me as strange is that when I deactivate the plugin, this function is also called from _exit_tree()
and it works, but it doesn’t throw an error. However, if I call it from _move_to()
, everything gets cleared and recreated in its correct place, but the two errors mentioned above are displayed. Do you have any ideas?
Additionally, for the complete code, you can go to the TopNote repository, and you’ll find these in the TopNote.gd
file, although I am still in the process of refining it, and this code is not exactly the same as the repository code.
Note: You can see here for more information, but I can not find any sulotion from that issue…