Here's a step-by-step guide to disable specific command-line arguments in game builds, without affecting the Godot editor:
We want to:
- Retain full functionality in the Godot editor binary for development.
- Customize and rebuild export templates so that the exported game binaries do not include debug-related command-line options like
--help
or--debug
.
This is achieved by modifying the export template code paths and compiling templates with tools=no
.
Follow the Godot official guide for compiling on Windows and ensure you have installed:
- Visual Studio 2022 with the "Desktop Development with C++" workload.
- Python 3.8+ with SCons:
python -m pip install scons
- Git to clone the Godot repository.
-
Open the Godot source code:
git clone https://github.com/godotengine/godot.git cd godot git checkout 4.3-stable
-
Open
main/main.cpp
in your code editor. -
Locate the section responsible for parsing command-line arguments. Typically, it looks like this:
for (int i = 1; i < argc; i++) { String arg = argv[i]; if (arg == "--help") { print_help(); return 0; } // Other arguments like debug options }
-
Comment out unwanted arguments only in export templates.
for (int i = 1; i < argc; i++) { String arg = argv[i]; // Disable debug-related options in exported builds. //if (arg == "--help") { // print_help(); // return 0; //} // Retain essential or custom arguments like --fullscreen if (arg == "--fullscreen" || arg.begins_with("--")) { OS::get_singleton()->set_fullscreen(true); } }
-
Save the changes.
-
Open the x64 Native Tools Command Prompt from Visual Studio.
-
Navigate to the Godot source directory:
cd path\to\godot
-
Compile the export templates with
tools=no
:- Debug template:
scons platform=windows target=release_debug tools=no -j8
- Release template:
scons platform=windows target=release tools=no -j8
- Debug template:
-
The compiled templates will appear in the
bin/
directory:godot.windows.opt.debug.64.exe
(debug export template).godot.windows.opt.release.64.exe
(release export template).
- Locate the export templates in your Godot installation:
- Default location:
C:\Users\<YourName>\AppData\Roaming\Godot\templates\4.x-stable
.
- Default location:
- Replace the default Windows templates with your custom-built binaries.
Alternatively:
- Use Editor > Manage Export Templates to configure a custom path for your templates.
- In Godot, export your project using the custom templates.
- Run the exported binary and test:
- Verify that debug options like
--help
or--debug
are no longer functional. - Confirm that essential options (e.g.,
--fullscreen
) still work as expected.
- Verify that debug options like
- These changes affect only the exported game binaries, leaving the editor binary fully functional.
- If you ever update Godot or use a newer version, you'll need to reapply these changes and rebuild the export templates.
This approach ensures a clean separation between the development environment and production builds, enhancing security for your shipped games.