Skip to content

fix(codegen): Initialize UPROPERTY fields in generated Unreal C++ code#3990

Merged
JasonAtClockwork merged 2 commits intoclockworklabs:masterfrom
brougkr:fix/unrealcpp-property-initialization
Jan 12, 2026
Merged

fix(codegen): Initialize UPROPERTY fields in generated Unreal C++ code#3990
JasonAtClockwork merged 2 commits intoclockworklabs:masterfrom
brougkr:fix/unrealcpp-property-initialization

Conversation

@brougkr
Copy link
Contributor

@brougkr brougkr commented Jan 9, 2026

Summary

UE5 strict mode requires all UPROPERTY fields to be explicitly initialized, otherwise the engine logs "property not initialized properly" errors at startup. This PR ensures generated Unreal C++ code properly initializes all UPROPERTY fields.

Changes

  • Modified cpp_ty_init_fmt_impl to accept module parameter for enum type resolution
  • Added initialization for enum types (PlainEnum) using the first variant as default value
  • Updated all call sites in reducer/procedure/struct generation to pass the module

Before

UPROPERTY(BlueprintReadWrite, Category="SpacetimeDB")
EMyEnumType SomeEnumField;  // ERROR: property not initialized properly

After

UPROPERTY(BlueprintReadWrite, Category="SpacetimeDB")
EMyEnumType SomeEnumField = EMyEnumType::FirstVariant;  // OK

Affected generated code

  • Reducer args structs (FXxxReducerArgs)
  • Reducer classes (UXxxReducer)
  • Procedure args structs (FXxxProcedureArgs)
  • Product type structs (FXxxType)

Test plan

  • Build codegen crate successfully
  • Generate bindings for a project with enum types
  • Verify generated code has proper initializers
  • Build Unreal project without "property not initialized properly" errors

Generated with Claude Code

UE5 strict mode requires all UPROPERTY fields to be explicitly
initialized, otherwise the engine logs "property not initialized
properly" errors at startup.

This change ensures generated reducer/procedure args structs and
reducer classes have proper initializers for:

- Primitive types (bool, int, float, etc.)
- Enum types (PlainEnum) - initialized to first variant

The `cpp_ty_init_fmt_impl` function now takes `module` as a parameter
to resolve enum type references and generate appropriate default
values like `= EMyEnumType::FirstVariant`.

Affected generated code:
- Reducer args structs (FXxxReducerArgs)
- Reducer classes (UXxxReducer)
- Procedure args structs (FXxxProcedureArgs)
- Product type structs (FXxxType)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Copy link
Contributor

@JasonAtClockwork JasonAtClockwork left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested and everything looks good to me. Thanks again!

UCLASS(BlueprintType)
class CLIENT_UNREAL_API UTestFunctionReducer : public UReducerBase
{
GENERATED_BODY()

public:
UPROPERTY(BlueprintReadOnly, Category="SpacetimeDB")
int32 X = 0;
UPROPERTY(BlueprintReadOnly, Category="SpacetimeDB")
int32 Y = 0;
UPROPERTY(BlueprintReadOnly, Category="SpacetimeDB")
ETestCType E = ETestCType::Foo;
};

@JasonAtClockwork JasonAtClockwork added this pull request to the merge queue Jan 12, 2026
Merged via the queue into clockworklabs:master with commit 30ab035 Jan 12, 2026
22 checks passed
kistz pushed a commit to kistz/SpacetimeDB that referenced this pull request Jan 13, 2026
clockworklabs#3990)

## Summary

UE5 strict mode requires all UPROPERTY fields to be explicitly
initialized, otherwise the engine logs "property not initialized
properly" errors at startup. This PR ensures generated Unreal C++ code
properly initializes all UPROPERTY fields.

### Changes

- Modified `cpp_ty_init_fmt_impl` to accept `module` parameter for enum
type resolution
- Added initialization for enum types (PlainEnum) using the first
variant as default value
- Updated all call sites in reducer/procedure/struct generation to pass
the module

### Before
```cpp
UPROPERTY(BlueprintReadWrite, Category="SpacetimeDB")
EMyEnumType SomeEnumField;  // ERROR: property not initialized properly
```

### After
```cpp
UPROPERTY(BlueprintReadWrite, Category="SpacetimeDB")
EMyEnumType SomeEnumField = EMyEnumType::FirstVariant;  // OK
```

### Affected generated code
- Reducer args structs (`FXxxReducerArgs`)
- Reducer classes (`UXxxReducer`)
- Procedure args structs (`FXxxProcedureArgs`)
- Product type structs (`FXxxType`)

## Test plan
- [x] Build codegen crate successfully
- [x] Generate bindings for a project with enum types
- [x] Verify generated code has proper initializers
- [x] Build Unreal project without "property not initialized properly"
errors

---
Generated with [Claude Code](https://claude.com/claude-code)

Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>
Co-authored-by: Jason Larabie <jason@clockworklabs.io>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants