How do you debug a plugin?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By wyattb

I have the following code and want to single step thru it in the Godot Editor debugger. Since this loads at Godot startup, is there a way I can debug it or at least move it to another node for debugging first?

tool
extends EditorPlugin

func _enter_tree():
	add_custom_type("MyButton", "Button", preload("my_button.gd"), preload("res://icon.png"))

func _exit_tree():
	remove_custom_type("MyButton")

Do you know about stepping through a game as it runs? Have you been able to run it in the editor? In the Debugger panel, there should be buttons for pausing the running game, stepping through functions, or stepping over functions.

Ertain | 2019-10-20 23:28

:bust_in_silhouette: Reply From: Zylann

You cannot use the editor to debug code that runs within itself. Any breakpoint would end up suspending the editor, including… the debugger’s UI^^"

However, the Godot editor is made the same way games are made with it (its controls are made of nodes within a scene tree, just like games, and your editor plugin scripts are part of that tree). It means you CAN debug it, but using the command line debugger instead. It is a bit more limited but is a great resource to investigate errors: Command line tutorial — Godot Engine (3.1) documentation in English

There was an issue open about this: Improve tool script debugging · Issue #5983 · godotengine/godot · GitHub

I even tried instantiating EditorPlugin by itself in a regular scene script. Will not allow it even though it inherits from Node. Print statements work as well as assert(false). Not sure if this is considered a hard breakpoint.

Another handicap is that you need to restart the plugin from Project every time you make a change.

wyattb | 2019-10-21 13:15