Godot: Custom features are not working with OS.has_feature or "Override for"

Created on 15 May 2020  路  7Comments  路  Source: godotengine/godot

Godot version:
GODOT 3.2.1 - released March 10, 2020

OS/device including version:
Windows 10 Home x64

Issue description:
When trying to export two different build, one for the client and one for the server, the custom features are not working.
If I create a new export template with a custom feature _server_build_, neither the Override for nor the OS.has_feature seem to be working.

I already saw this issue for the override and this other one for the OS access, but I can't get it working. I just downloaded the latest version of the engine with no success.

Steps to reproduce:

  1. Export the repo with the default features

    • Should show a main screen with a label "Client Build" and printing in the console "The client build"

  2. Export the repo with a custom feature _server_build_

    • EXPECTED Should show a main screen with a label "Server Build" and printing in the console "The server build"

    • RESULT The same main screen and console output are shown, as if the build was made without the custom feature

Minimal reproduction project:
custom_feature_bug.zip

archived bug confirmed core

Most helpful comment

Okay, that was a bug that I've been facing since the beginning of my project around 2 months ago. I couldn't think of any workarounds or fixes up until now.

Hopefully it gets properly fixed soon - commeting the if/else to get server/client version of my project for n'th time was driving me insane and today I figured out this temp solution.

Instead of using custom feature to differentiate between server and client - do it through executable name:

func check_if_server() -> bool: return OS.get_executable_path().ends_with("Server.exe")

Hope it serves you well for the time being. Cheers!

All 7 comments

Okay, that was a bug that I've been facing since the beginning of my project around 2 months ago. I couldn't think of any workarounds or fixes up until now.

Hopefully it gets properly fixed soon - commeting the if/else to get server/client version of my project for n'th time was driving me insane and today I figured out this temp solution.

Instead of using custom feature to differentiate between server and client - do it through executable name:

func check_if_server() -> bool: return OS.get_executable_path().ends_with("Server.exe")

Hope it serves you well for the time being. Cheers!

Thanks @Luzkan I'll give it a try!

Any word on a fix? This is a bad blocker for me as Im trying to create a client and server in one project. Can't build either without modifying code between exports

@systemsoverload I don't think anyone is working on a fix right now, but as a workaround, you could:

  • Use environment variables using OS.get_environment().
  • Check for the presence of a file in the same directory as the executable.
  • Check the executable name (https://github.com/godotengine/godot/issues/38747#issuecomment-633588157).
  • And probably more...

Another idea: let your build script change constant variables in your .gd file between Exports. Maybe you got a auto-loaded Constants.is_server=true, you can automatically change to false before exporting a client.

I'm using a python script to build, deploy and publish my game, and I do this kind of thing to set a version number that both server and client can read and check for. As far as I know, such a game version attribute is badly missing in godot too. You can set version attributes for some exports (not all of them) but you can't read them from code.

@mrimvo There's a pull request that implements a version project setting: #35555

This is another bug actually, see #42978
Everything will work when you move the executable outside your project directory.

Was this page helpful?
0 / 5 - 0 ratings