-
-
Notifications
You must be signed in to change notification settings - Fork 21.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Preprocessor defines for C#/Mono #27227
Comments
Unity uses this to allow conditional compiling of code based on the version of Unity being used. This might be an ok thing to have, but I'm more interested in compiling for the engine as a whole rather than any specific version, which is actually something Unity lacks. |
Unity has had this feature since Unity 5.3 (released in 2015). |
Disappointing to see that this has been around in C# for over 25 years, Unity has had it implemented for more than a decade, but GoDot still doesn't have any plans to implement this in the foreseeable future. Quite a huge oversight, especially when you consider cross-engine library support, client versus server environments, and any other use case. |
@Akrucious It is implemented in Godot. |
The documentation says you can't define them. |
Where does it say that you can't define them (genuine question, I don't find that statement)? I'm pretty sure you can add any constant via
This is a standard .NET feature and not specific to Godot. We could document it in the linked page though. And this closed issue was resolved by adding some automatically defined constants specific to Godot that you don't need to define manually, as documented in the linked page. |
Not sure if you realize this but manually specifying them overrides the GoDot defined ones, bricking the engine. |
Make sure you are appending to <DefineConstants>$(DefineConstants);MY_CONSTANT</DefineConstant> |
That actually works, thank-you raulsntos, you're awesome! |
The what: It would be great if Godot could automatically add a preprocessor define to the project for Mono. I believe Unity has done this since version 2.6.0.
The why: It's very convenient to be able to use the same source code in different places. I have built and still maintain a C# library for reading BSP files (from the Source engine, for example), and I've been able to make it work in .NET standalone projects as well as Unity by using Unity's C# preprocessor defines. I'd love to add support for Godot the same way. The project is at https://github.com/wfowler1/LibBSP
The how: It would probably be sufficient to simply add "GODOT" to the DefineConstants section of each build configuration in the CSPROJ. Then in C# code we could simply wrap Godot-specific code in
#if GODOT
andENDIF.
The text was updated successfully, but these errors were encountered: