Conditional code stripping

Godot Version

4.2.1

Question

Hello there!

I’m currently converting my game from Unity to Godot 4.2 with .NET. It’s a multiplayer game with shared codebase within a single project. In Unity, it’s possible to strip parts of code via conditional compilation symbols (defines), such as UNITY_SERVER for dedicated server.

It seems there is a GODOT_SERVER definition available, however, it does nothing in my case. GODOT_SERVER is simply false when I export and run a dedicated server build. Is there something I miss? Is this compilation symbol available only on Linux, for example? Or is there any other way to strip server code from client build?

did you check it from OS.has_feature?

Yes, it’s not the same thing, unfortunately. While OS.HasFeature is excellent for runtime checks, preprocessor directives (such as GODOT_SERVER) are being checked in compile time, and code enveloped in such condition will not be compiled in the final EXE. Which is what I want - I don’t want to include server code in the client at all (and vice versa).

So far, most viable option seems to have a separate scene for server that can be removed on project build. It’s not the most convenient way but it works :slight_smile: