godotengine / godot-proposals

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

Add signals `breakpoint` and `assertion_failed` to `Engine` class #2762

Open Error7Studios opened 3 years ago

Error7Studios commented 3 years ago

Describe the project you are working on

Debug logging script

Describe the problem or limitation you are having in your project

I have a generic Handler class that I'm using to handle all signal emissions in my project. I'm storing debug messages in a ring buffer, and I want to write them to a file on breakpoint or failed assert(). (Basically whenever the game is paused or stopped) However, I don't see any way to do that.

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

Add signals breakpoint and assertion_failed to Engine class

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

func _ready() -> void:
    Engine.connect("breakpoint", self, "log_debug_messages")
    Engine.connect("assertion_failed", self, "log_debug_messages")

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

I couldn't find any way to do this with script.

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

Seems like it has to be implemented in core.

Xrayez commented 3 years ago

The functionality behind assert() and breakpoint may be specific to GDScript. For registering assert messages, I think this could be handled on the level of:

See also #1763 which is kind of the "opposite" of this proposal.

Speaking generally, there's a plugin which does help with logging part, see https://github.com/KOBUGE-Games/godot-logger, and I think it's the best alternative we have for now.

Error7Studios commented 3 years ago

The functionality behind assert() and breakpoint may be specific to GDScript

Good point. SceneTree has a paused property. If it emitted a pausing signal, that might work for both breakpoint and assert().

see https://github.com/KOBUGE-Games/godot-logger

Thanks! Overkill for what I need it for, but a great reference.