godotengine / godot-docs

Godot Engine official documentation
https://docs.godotengine.org
Other
3.97k stars 3.23k forks source link

Document how the Godot binary loads projects, and how to load external Godot projects from a Godot launcher with OS.execute #3593

Open tx350z opened 4 years ago

tx350z commented 4 years ago

Godot version:

v3.2.stable.official

OS/device including version:

N/A

Issue description:

Running "app1" in the Godot editor. App1 calls OS.execute to launch "app2.exe" which is another Godot app created using Windows Desktop export template with debug turned off. Instead of running app2.exe, a second instance of app1 ran.

When I export app1 using the Windows Desktop export template and run the app1.exe, OS.execute launches the correct app (app2.exe)

Steps to reproduce: 1) Create a simple project and export to "path/app2.exe" using Windows Desktop export template with debug turned off. Verify this app runs correctly when launched manually.

2) Create a second simple projected called "app1" with a button that when clicked calls OS.execute("path/app2.exe",[],false).

3) Run app1 in the editor, click the button. A second instance of app1 appears.

4) Export app1 to "path/app1.exe" using the Windows Desktop export template with debug turned off.

5) Launch app1.exe and click the button. app2.exe is executed correctly.

Minimal reproduction project:

Calinou commented 4 years ago

If you exported both executables in the project root folder, maybe this is because the project data takes priority over the PCK file?

Also, did you check the "embed PCK in executable" option in the export dialog? This is a known bug which has been fixed in the 3.2.2 betas.

tx350z commented 4 years ago

Thanks. Embedding the PCK is a good idea but did not solve the problem. The interesting thing is if the target app is not a Godot app, the correct binary is run. The correct binary is also run if I export both apps to Windows and run the exe. So it has to be a bug in the editor/debugger.

I'm putting together very simple projects to demonstrate the problem. Will add the zips when I can.

akien-mga commented 4 years ago

The correct binary is properly run, but Godot binaries are all the same, it's the presence of a .pck or project.godot file in the current folder which determines which project will run.

If you want to start a different project from your current Godot project, you can even reuse the current Godot binary (OS.get_executable_path() -- provided it's a project for the same Godot version), but you need to give it the --main-pack argument pointing to the .pck you want to load. Otherwise it will load your current project's project.godot from your current working directory.

akien-mga commented 4 years ago

Moving this to godot-docs as we should add a page or section related to the behavior of the Godot binary when loading projects, and how to run external Godot-based projects from a Godot application (e.g. game launcher).

akien-mga commented 4 years ago

Relevant documentation: https://github.com/godotengine/godot/blob/0183bfbb0f8481cbb7886b48c8d55b788b92e253/core/project_settings.cpp#L293-L317

tx350z commented 4 years ago

I'm not trying to disagree, just understand why OS.execute() behaves differently when called by an app run in the editor and when called by the same app once compiled.

Attached is a zip containing three folders; two Godot project folders, and a folder for holding exported Windows binaries.

1) Unzip to a folder of your choosing. 2) Import osexec_child project into Godot. 3) Do a Windows export (note Embed PCK is checked). Verify ../osexec_bins/osexec_child.exe runs correctly. 4) Click Project/Exit to Project List. 5) Import osexec_parent project into Godot and run it (F5) 6) Clicking the button launches a second instance of oexec_parent, not ../osexec_bin/osexec_child.exe 7) Do a Windows export of osexec_parent (Embed PCK is checked) 8) Run ../osexec_bins/osexec_parent.exe 9) Clicking the button correctly launches osexec_child.exe

Many thanks for all the great work you folks do.

osexec_oddness.zip