clockworklabs/SpacetimeDB · error · anyhow::Error

--uproject-dir is required for --lang unrealcpp

Error message

--uproject-dir is required for --lang unrealcpp

What it means

Unreal C++ binding generation emits a plugin into an Unreal Engine project, so generate must know the directory containing your `.uproject` file. When the resolved language is `unrealcpp` and neither the `--uproject-dir` flag nor an `uproject-dir` value in spacetime.json is present, the CLI rejects the invocation before doing any work. This is a deliberate pre-flight check so the more specific Unreal errors surface before generic path checks.

Source

Thrown at crates/cli/src/subcommands/generate.rs:345

        let namespace = command_config
            .get_one::<String>("namespace")?
            .unwrap_or_else(|| "SpacetimeDB.Types".to_string());
        let module_name = command_config.get_one::<String>("unreal_module_name")?;
        let module_prefix = command_config.get_one::<String>("module_prefix")?;
        let build_options = command_config
            .get_one::<String>("build_options")?
            .unwrap_or_else(String::new);
        let dotnet_version = if command_config.is_from_cli("dotnet_version") {
            command_config.get_one::<u8>("dotnet_version")?
        } else {
            let dotnet_version = command_config.get_one::<String>("dotnet_version")?;
            parse_optional_dotnet_version(dotnet_version.as_deref())?
        };

        // Validate Unreal-specific args first to preserve focused errors for this mode.
        if requested_lang == Some(Language::UnrealCpp) {
            if command_config.get_one::<PathBuf>("uproject_dir")?.is_none() {
                return Err(anyhow::anyhow!("--uproject-dir is required for --lang unrealcpp"));
            }
            if module_name.is_none() {
                return Err(anyhow::anyhow!("--unreal-module-name is required for --lang unrealcpp"));
            }
        }

        // Validate module source path for source-based generation.
        if wasm_file.is_none() && js_file.is_none() && !project_path.is_dir() {
            anyhow::bail!(
                "Could not find module source at '{}'. \
                 If this is not correct, pass --module-path or add module-path in spacetime.json. \
                 You can also pass --bin-path/--js-path to generate without building from source.",
                project_path.display()
            );
        }

        let lang = match requested_lang {
            Some(lang) => lang,

View on GitHub (pinned to 524b4487d9)

Solutions

  1. Pass `--uproject-dir /path/to/MyProject` pointing at the folder that contains MyProject.uproject
  2. Add `"uproject-dir": "..."` to the unrealcpp target in spacetime.json so the flag isn't needed every run
  3. Verify the directory actually contains a .uproject file

Example fix

# before
spacetime generate --lang unrealcpp

# after
spacetime generate --lang unrealcpp --uproject-dir ~/Projects/MyGame --unreal-module-name MyGame
Defensive patterns

Strategy: validation

Validate before calling

# Guard an unrealcpp generate invocation:
if [[ "$LANG_ARG" == "unrealcpp" ]]; then
  [[ -n "$UPROJECT_DIR" ]] || { echo "unrealcpp requires --uproject-dir" >&2; exit 2; }
  ls "$UPROJECT_DIR"/*.uproject >/dev/null 2>&1 \
    || { echo "no .uproject file in $UPROJECT_DIR" >&2; exit 2; }
fi
spacetime generate --lang "$LANG_ARG" --uproject-dir "$UPROJECT_DIR"

Prevention

When it happens

Trigger: `spacetime generate --lang unrealcpp` with no `--uproject-dir`; an unrealcpp target in spacetime.json that omits `uproject-dir`.

Common situations: Running generate from the server module directory instead of the UE project root; CI scripts copied from rust/typescript invocations; newly switching an existing target to unrealcpp.

Related errors


AI-assisted analysis of clockworklabs/SpacetimeDB@524b4487d9 (2026-08-16). Data as JSON: /api/errors/5f5880ad2967f15a. Report an issue: GitHub.