GDScript equivalent of C# DEBUG preprocessor directive?

Godot Version

4.2

Question

How can I run some code only in Debug builds of my game? Specifically, I’d like to draw some debug information using CanvasItem._draw() but only when the game is running as a debug build.

In C# we are able to use the DEBUG preprocessor directive, e.g:

public partial class DebugStuff : Node
{
	public override void _Ready()
	{
#if DEBUG
		GD.Print("RAN SOME DEBUG CODE!");
#endif
	}
}

GDScript does not have preprocessor directives. You can use Feature tags — Godot Engine (stable) documentation in English for that.

func _ready() -> void:
	if OS.has_feature('debug'):
		print('Debug build')
2 Likes

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.