This little project was inspired by this reddit post asking if print messages can link back to the source script in the editor.
Since the Godot editor is powered by the Godot Engine, it's possible with an EditorPlugin.
The plugin does two things:
- Provide a "gg" singleton/autoload with a
print()
method that usesprint_rich()
to print messages with link that contain the stack trace (viaget_stack()
). - Attach a "meta_clicked" signal handler to the EditorLog (the output panel), so that clicks on the link can be opened in the editor.
With that, it's possible to call:
gg.print("Clicking me links back to the source file.")
Run the main.tscn
scene and click the buttons to see print messages in the output.
Clicking the messages will take you to the script source where they were called.
-
Since this is an editor plugin, it won't run for exported games, which means the
gg
autoload won't be available, which means errors. You'd have to either remove all thegg.print()
calls, search and replace them all with a regularprint()
statement, or autoload a dummy script, sogg.print()
is available. -
gg.print()
also only accepts a string, variadic functions are still in the proposal stage.
This is only a proof of concept.
EditorInterface
helps when creating editor plugins, but I was surprised that there's no clean, good way to get access to any of the existing panels.
You have to traverse the tree yourself, which feels a bit brittle.
The EditorLog defines the node structure in the source.