A built-in function call that calls another function but gets removed if the build is not debug
Much in the vain as void assert(test : bool) we can have
# signature
void debug_call(object : Object, method : String, args... : Variant...)
# and in practice
debug_call(self, "draw_path", path, Color.red)
A debug method call would be nice for calling test methods while in debug, but want to remove during release.
I have a bunch of debug drawn lines on screen to help me out and it'd be hassle to turn them all off when I want to demo a project for a friend, for example. It'd be better if I could just export in release and be done with it.
There are two methods for not calling a method in a debug build:
OS.is_debug_build() as a hint and only run the method if the former is true.if statements everywhere with the same OS.is_debug_build() gets old and ugly.
My current workaround to avoid the above is something like this:
static func debug_call(obj : Object, method : String) -> void:
assert(_call(obj, method))
static func _call(obj : Object, method : String) -> bool:
obj.call(method)
return true
This is pretty much an empty method call when compiled for a release build, since asserts get completely skipped in compilation on non-debug builds.
Thoughts on this?
You can use
if OS.is_debug_build():
your_debug_function()
or make it a debug_call function as above with the if OS.is_debug_build() inside.
@akien-mga I think the point is that doing an if like this has a writing cost and a runtime cost in release, or worse, could not compile at all due to using functionality within the block that only exists in the editor project. The C# equivalent to this proposal would be conditional function attributes, which are usually found on functions like LogDebug() or DrawGizmo(), so coders don't have to systematically wrap every call with an if and they won't pay the cost of processing the arguments (which could be some string format or data-gathering function call as well). Not sure if all that is doable in GDScript, but that's an everyday use case I know of.
I suggest a debug block that is skipped in runtime builds
debug:
#do code that is only executed in debug builds
#do some more code
So for you example,
debug: draw_path(path, Color.red)
Feature and improvement proposals for the Godot Engine are now being discussed and reviewed in a dedicated Godot Improvement Proposals (GIP) (godotengine/godot-proposals) issue tracker. The GIP tracker has a detailed issue template designed so that proposals include all the relevant information to start a productive discussion and help the community assess the validity of the proposal for the engine.
The main (godotengine/godot) tracker is now solely dedicated to bug reports and Pull Requests, enabling contributors to have a better focus on bug fixing work. Therefore, we are now closing all older feature proposals on the main issue tracker.
If you are interested in this feature proposal, please open a new proposal on the GIP tracker following the given issue template (after checking that it doesn't exist already). Be sure to reference this closed issue if it includes any relevant discussion (which you are also encouraged to summarize in the new proposal). Thanks in advance!
Most helpful comment
I suggest a debug block that is skipped in runtime builds
So for you example,