Command Line Troubles

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By DDoop

I’m trying to set up a batch file that will run a specific scene from my project (temporarily going to be using a smaller display than usual, and the Godot editor has a ton of negative space that impedes my productivity, so I want to use Notepad++).

When I run godot --editor "C:\Users\dupui\Desktop\Godot\CitySim\2D PoC\Gen2\Gen2Testing.tscn" --upwards at the prompt though, I get this error:

**ERROR**: Condition "err" is true. Returned: err
   At: modules/gdscript/gdscript.cpp:829:load_source_code() - Condition "err" is true. Returned: err
**ERROR**: Cannot load source code from file 'res://2D PoC/Gen2/Scripts/Gen2Testing.gd'.
   At: modules/gdscript/gdscript.cpp:2286:load() - Condition "err != OK" is true. Returned: RES()
**ERROR**: Failed loading resource: res://2D PoC/Gen2/Scripts/Gen2Testing.gd. Make sure resources have been imported by opening the project in the editor at least once.
   At: core/io/resource_loader.cpp:278:_load() - Condition "found" is true. Returned: RES()
**ERROR**: res://CitySim/2D PoC/Gen2/Gen2Testing.tscn:3 - Parse Error: [ext_resource] referenced nonexistent resource at: res://2D PoC/Gen2/Scripts/Gen2Testing.gd
   At: scene/resources/resource_format_text.cpp:440:poll() - res://CitySim/2D PoC/Gen2/Gen2Testing.tscn:3 - Parse Error: [ext_resource] referenced nonexistent resource at: res://2D PoC/Gen2/Scripts/Gen2Testing.gd
**ERROR**: Failed to load resource 'res://CitySim/2D PoC/Gen2/Gen2Testing.tscn'.
   At: core/io/resource_loader.cpp:208:load() - Condition "err != OK" is true. Returned: RES()
**ERROR**: Failed loading resource: res://CitySim/2D PoC/Gen2/Gen2Testing.tscn. Make sure resources have been imported by opening the project in the editor at least once.
   At: core/io/resource_loader.cpp:278:_load() - Condition "found" is true. Returned: RES()
**ERROR**: Failed loading scene: res://CitySim/2D PoC/Gen2/Gen2Testing.tscn
   At: main/main.cpp:1944:start() - Condition "!scene" is true. Returned: false
**WARNING**: ObjectDB instances leaked at exit (run with --verbose for details).
   At: core/object.cpp:2135:cleanup() - ObjectDB instances leaked at exit (run with --verbose for details).

This happens if I use --debug instead of --editor as well (I would like to be just using --debug but I’m experimenting with different flags to get it to work.

When I run the scene from in the editor (and I have multiple times, so I’m not sure why the error I’m getting suggests I try that), it opens just fine with no complaints.

The batch file (and the godot.exe) are 1 directory up from the project’s .godot file. This directory with the .bat and the .exe is on the path, and my godot.exe is literally named godot.exe.

I have also tried placing the .gd file attached to the .tscn in the same file as the .tscn, and that returned the same error. I’ve also tried running the batch file with elevated permissions (make a shortcut, run shortcut as admin), and that also fails to work (and also does not generate a log file on my device). Any advice? Does every file have to be local/embedded in the .tscn file for the command prompt to work? That would really suck.

I don’t think any of the --verbose information is helpful, but I uploaded it to a pastebin here.

:bust_in_silhouette: Reply From: jgodfrey

While there might be other ways to do it, I think something like this should work:

godot "path/to/project.godot" -e "your_scene.tscn"

So, with a directory structure like:

C:\
    Godot\
        MyGame\
            project.godot
            Scenes\
                Bullet.tscn

This should work to load Bullet.tscn

godot C:\Godot\MyGame\project.godot -e Scenes\Bullet.tscn

I created a simple test project to try and make it work under ideal circumstances and I still can’t jump right into a scene with the --debug flag. It’s failing to load the scene file.
I have a shortcut to godot.exe (and it’s in my path) in D:\Godot. The same directory also contains a project folder, CmdDebug. This is the filestructure:

D:\
  Godot\
    debug_command_prompt.bat
    godot.exe
    CmdDebug\
      project.godot
      Scenes\
        Bullet.tscn (just a sprite with the Godot icon)

debug_command_prompt.bat:

godot --path "D:\Godot\CmdDebug\project.godot" --debug "Scenes\Bullet.tscn"

I have also tried

godot -u --debug "Scenes\Bullet.tscn"

I’m getting this result:

Godot Engine v3.2.3.stable.official - https://godotengine.org
OpenGL ES 3.0 Renderer: GeForce GTX 970/PCIe/SSE2
 
**ERROR**: Cannot open file 'res://Scenes/Bullet.tscn'.
   At: scene/resources/resource_format_text.cpp:1228:load_interactive() - Condition "err != OK" is true. Returned: Ref<ResourceInteractiveLoader>()
**ERROR**: Failed loading resource: res://Scenes/Bullet.tscn. Make sure resources have been imported by opening the project in the editor at least once.
   At: core/io/resource_loader.cpp:278:_load() - Condition "found" is true. Returned: RES()
**ERROR**: Failed loading scene: res://Scenes/Bullet.tscn
   At: main/main.cpp:1944:start() - Condition "!scene" is true. Returned: false
**WARNING**: ObjectDB instances leaked at exit (run with --verbose for details).
   At: core/object.cpp:2135:cleanup() - ObjectDB instances leaked at exit (run with --verbose for details).

So, it’s finding the .tscn file, but then somewhere it checks to verify the file is indeed a scene and that check is failing? Am I understanding this correctly?

DDoop | 2020-12-17 00:01

First, I just edited my earlier command line example because it had an extra -e in it so you might look at that again.

I will say that --path seems to cause similar errors here for me. Leaving it out works fine for me.

So, again, this for a basic command line to open a scene file:

godot C:\Godot\MyGame\project.godot -e Scenes\Bullet.tscn

For the structure I listed above.

That said, I don’t know anything about the --debug option.

jgodfrey | 2020-12-17 00:25

I’ll phrase the question more generally:
How do I jump straight into a scene (with debug output in the console) as if I had launched that scene from the editor, by only running a batch file? Is this possible? I only substituted -e for -d because I couldn’t get -d to work and I wanted to make sure that I wasn’t doing everything wrong. I can get the editor to open a specific scene by this point, but that isn’t my end goal; I’d like to avoid the editor altogether for a short period.

DDoop | 2020-12-17 00:33

OK, I think I understand what you’re after. Unfortunately, I can’t come up with any satisfactory command line here either. That said, it may very-well be possible, but I can’t seem to figure it out either.

And, the “–path” arg definitely seems to cause some heartburn here…

jgodfrey | 2020-12-17 01:26

:bust_in_silhouette: Reply From: Calinou

Running the following line while in the project root should work:

godot Scenes\Bullet.tscn

If you’re not in the project root, use:

godot --path C:\Godot\MyGame C:\Godot\MyGame\Scenes\Bullet.tscn

--path should specify the path to the project folder, not the project.godot file.

You can also add the --upwards argument to make Godot scan upwards for a project.godot file. This is useful if your CWD is in a subdirectory of the project, so you don’t have to the specify --path manually.