Godot have a conditional compilation feature


In Godot, can we decide whether or not to compile certain lines of code with a condition?
For example:

#if Runtime == DEBUG
some code functions etc..

#elif Platform == Platform.Android


This feature is needed for things like cross-platform custom code and code security.

In GDScript is not possible. The most you have access are feature tags to control which part of the code will run.

1 Like

There is no preprocessor directives in GDScript, but you can use feature flags with if OS.has_feature(name) for the same functionality.

More details here:

thanks, i wish this will be added in the next godot releases.

you would have to wish for it there first, maybe someone has already wished for something similar, then you could ‘push’ it