0
\$\begingroup\$

In a number of other engines I've worked with, including Unreal and Unity, there's been support for not only preprocessor commands, but conditional compilation based on platform. As an example, in Unity, I could do this:

#if UNITY_STANDALONE_WIN

And, the following code, until the #endif, would only be included if I was compiling for the Windows platform. This is very similar to building with something like gcc and including the -D flag for directives, so it isn't new. Additionally, I've noted that when compiling on Godot, I can include the same platform multiple times, allowing for variation.

Suppose I wanted to compile a demo version of my game, using the Godot engine, which only included the first few levels; and a full, premium version, which included the whole thing. I would want both to have feature parity. If I could detect which export template I was using, I could automatically cut the demo off at the correct point, and build the premium version for the full game, at the same time, by selecting "Export All..." compared to manual changes or multiple projects, that's a big win for me.

Currently I'm using the non-Mono version of Godot, and GDScript with occasional GDExtensions C++. GDScripts fundamental design principles preclude a precompiler like C's, but changing a field based on export settings would be more than enough for me. I'm open to C# answers, but I ultimately need to get it to work with GDScript. Can someone help me figure out how to change values based on export template so I can be selective when building my code?

\$\endgroup\$

1 Answer 1

1
\$\begingroup\$

Searching for "Godot conditional compilation" led me to this GitHub discussion proposing the feature, though to less-than-rave reviews.

In the comments, someone linked a proposal to preprocess scripts based on feature tags, which is currently "Open", though similar issues have been closed in the past.

Another user, dalexeev, commented that they have made a preprocessor plugin that performs this function. I have not used this and cannot vouch for it personally, though it's been updated within the past 6 months, so it seems to be relatively recently maintained.

\$\endgroup\$
1
  • \$\begingroup\$ I think that will do it actually; I didn't realize I could add custom features, too. Thank you! I don't exclusively need a preprocessor; but the ability to automatically and conditionally detect facets of the platform or release template is going to be a major time saver. \$\endgroup\$ Commented Nov 2, 2023 at 14:53

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .