godotengine / godot-proposals

Godot Improvement Proposals (GIPs)
MIT License
1.14k stars 96 forks source link

Allow spawning a separate Godot instance to debug a specific plugin #6946

Open bitbrain opened 1 year ago

bitbrain commented 1 year ago

Describe the project you are working on

I am currently developing an add-on for the Godot Engine that enables the generic definition of RPG data, mirroring the functionality of solutions such as GridlessDB. Seamlessly integrated within the Godot editor, this add-on offers an innovative alternative to the traditional usage of .tres resource files for data specification in Godot. Instead, it introduces a hierarchical/graph-based organization of data, a paradigm shift designed to not only enhance the clarity of data relationships but also significantly optimize data loading performance.

Describe the problem or limitation you are having in your project

While working on this addon I have encountered some challenges that would slow me down during development:

Challenges with Debugging addons in the Godot Editor

Debugging addons within the Godot editor presents a significant issue, primarily because setting breakpoints within the addon's initialization code has the potential to halt the engine itself. While this technical constraint is comprehensible, providing a more thorough debugging mechanism for addons would greatly assist developers in identifying and resolving issues. This problem becomes even more complex for addons developed as GDExtensions, given their C++ codebase as opposed to GDScript.

Identifying the cause of addon activation failures is complex

An example of this issue can be seen when a script contains a typo, preventing its correct loading. If that script is utilized by the addon, the addon simply fails to activate without providing a clear reason. Consequently, developers are forced to sift through error logs to identify potential causes of the failure, a process that can be both time-consuming and confusing.

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

To address these challenges, I propose the introduction of a refined debugging mechanism specifically tailored for addons within the Godot editor. This would involve creating a system that allows for in-editor debugging of addons without compromising the editor's performance or functionality.

In the event of an addon encountering a loading error, the engine should automatically direct the developer to the exact line of code that caused the error. Once the error is rectified, the engine should then either automatically enable the addon or proceed to the next error impeding the correct initialization of the addon.

This change will speed up the debugging process, make addons more reliable, and create a smoother, more productive development workflow. Additionally, we need a way to test the addon in a separate Godot instance, not in the current active editor. This could be done by starting a second Godot process in the background while debugging the addon. We could introduce a 'debug addon mode' switch to activate this feature. In this mode, the addon won't load in the current Godot editor but in an isolated Godot process. This allows independent debugging with breakpoints.

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

Let us say in the addons section is a new button called 'debug' that allows me to debug this addon in isolation.

Capture2

Clicking this button will spawn a new instance of Godot with the addon activated:

Capture

Note, that now in the main Godot window I can set breakpoints and jump through the loading process of the addon itself.

Capture

There could also be a button somewhere to quickly 'reload' the particular addon.

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

I do not know of any workaround for this. Please let me know in the comments if there is an easy way to debug addons that I might be unaware of!

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

Developing addons is part of the core experience of Godot developers. Any person who intends to build an addon for the Godot editor will face the issues I have described above and I do not see how an addon could solve these problems.

DarkMessiah commented 1 year ago

Have you tried this https://godotengine.org/asset-library/asset/1807?