Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions crates/cli/src/subcommands/generate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ fn build_generate_config_schema(command: &clap::Command) -> Result<CommandSchema
.key(Key::new("js_file").module_specific())
.key(Key::new("namespace").generate_entry_specific())
.key(Key::new("unreal_module_name").generate_entry_specific())
.key(Key::new("module_prefix").generate_entry_specific())
.key(Key::new("build_options").module_specific())
.key(Key::new("include_private"))
.exclude("json_module")
Expand Down Expand Up @@ -234,6 +235,11 @@ pub fn cli() -> clap::Command {
.alias("module-name")
.help("The module name that should be used for DLL export macros (required for lang unrealcpp)")
)
.arg(
Arg::new("module_prefix")
.long("module-prefix")
.help("The module prefix to use for generated types (only used with --lang unrealcpp)")
)
.arg(
Arg::new("lang")
.long("lang")
Expand Down Expand Up @@ -285,6 +291,7 @@ pub struct GenerateRunConfig {
pub lang: Language,
pub namespace: String,
pub module_name: Option<String>,
pub module_prefix: Option<String>,
pub build_options: String,
pub out_dir: PathBuf,
pub include_private: bool,
Expand Down Expand Up @@ -313,6 +320,7 @@ fn prepare_generate_run_configs<'a>(
.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);
Expand Down Expand Up @@ -371,6 +379,7 @@ fn prepare_generate_run_configs<'a>(
lang,
namespace,
module_name,
module_prefix,
build_options,
out_dir,
include_private,
Expand Down Expand Up @@ -512,6 +521,7 @@ pub async fn run_prepared_generate_configs(
unreal_cpp_lang = UnrealCpp {
module_name: run.module_name.as_ref().unwrap(),
uproject_dir: &run.out_dir,
module_prefix: run.module_prefix.as_deref().unwrap_or(""),
};
&unreal_cpp_lang as &dyn Lang
}
Expand Down
1 change: 1 addition & 0 deletions crates/codegen/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ spacetimedb-schema.workspace = true
anyhow.workspace = true
convert_case.workspace = true
itertools.workspace = true
serde_json.workspace = true

[dev-dependencies]
fs-err.workspace = true
Expand Down
13 changes: 11 additions & 2 deletions crates/codegen/src/UnrealCPP-README.md
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,7 @@ cargo run --bin spacetimedb-cli -- generate --lang unrealcpp --uproject-dir crat
### Parameters

- `--lang unrealcpp`: Specifies the UnrealCPP code generator
- `--uproject-dir`: Directory containing Unreal's .uproject or .uplugin file
- `--uproject-dir`: Directory containing your Unreal project's `.uproject` file
- `--module-path`: Path to your SpacetimeDB module source code
- `--unreal-module-name`: **Required** - Name used for generated classes, API prefix and putting generated module bindings in the correct Module's Source

Expand All @@ -331,6 +331,15 @@ The `--unreal-module-name` parameter is **mandatory** for UnrealCPP generation b

**⚠️ IMPORTANT:** Without the module name, the generated code would not compile in Unreal Engine due to missing API macros and naming conflicts.

### Project Setup Behavior

When generating into an Unreal project, the code generator also:

1. Ensures the named module exists in the project's `Modules` array in the `.uproject` file.
2. Creates missing `Source/<Module>/<Module>.Build.cs`, `Source/<Module>/<Module>.cpp`, and `Source/<Module>/<Module>.h` files.

If the `.uproject` file is missing, unreadable, malformed, or has an invalid `Modules` field, generation fails immediately.

## Implementation Details

The Blueprint compatibility checking is implemented in the `is_blueprintable()` function, which recursively checks:
Expand All @@ -344,4 +353,4 @@ All error messages follow a consistent format:
- **Single type:** `"uint32 types are not Blueprint-compatible"`
- **Multiple types:** `"uint32, uint64 types are not Blueprint-compatible"`

This makes it clear to developers exactly which types need to be changed for Blueprint compatibility.
This makes it clear to developers exactly which types need to be changed for Blueprint compatibility.
Loading
Loading