Repository navigation
Advanced Features
Mirrored from
ADVANCED_FEATURES.mdin the repo root. Edit the source file and re-sync this page rather than editing only here.
- Incremental Build System
- Runtime Metadata Generation
- Hot Reload Support
- Fluent API Extension Methods
- Default Parameter Values
- MSBuild Task Integration
The binding generator now supports incremental builds using SHA256 file hashing and a JSON cache file.
- File Hashing: Each header file is hashed using SHA256
- Configuration Hashing: The binding configuration is also hashed
-
Cache Storage: Hashes are stored in
.binding_cache.json - Change Detection: Only regenerates when files or config change
# Normal build (uses cache)
O3DESharp.BindingGenerator generate --project ./project.json
# Force full rebuild
O3DESharp.BindingGenerator generate --project ./project.json --force
# Disable incremental builds
O3DESharp.BindingGenerator generate --project ./project.json --incremental falseIn binding_config.json:
{
"global": {
"incrementalBuild": true,
"cacheFilePath": ".binding_cache.json"
}
}- Caching/FileHasher.cs - SHA256 hash computation
- Caching/BuildCache.cs - Cache management
The generator now produces runtime reflection metadata for each gem, enabling hot reload and dynamic binding resolution.
For each gem, the following files are generated:
-
Metadata.g.cs- Strongly-typed metadata classes -
metadata.json- JSON metadata for tooling
using O3DE.MyGem;
// Get class metadata
var classInfo = BindingMetadata.GetClass("PhysicsComponent");
if (classInfo != null)
{
Console.WriteLine($"Methods: {classInfo.Methods.Length}");
Console.WriteLine($"Properties: {classInfo.Properties.Length}");
}
// Enumerate all bindings
foreach (var cls in BindingMetadata.Classes)
{
Console.WriteLine($"Class: {cls.Name} ({cls.Methods.Length} methods)");
}In binding_config.json:
{
"global": {
"generateMetadata": true
}
}The binding system now supports hot reloading C# script assemblies without restarting the editor.
- State Preservation: Serializable field values are saved before unload
- Assembly Versioning: Reload generation tracking for debugging
- Event System: Subscribe to reload events for custom handling
- Automatic Registration: Generated C++ code includes hot reload hooks
using O3DE.Core.HotReload;
// Register a script for hot reload tracking
HotReloadManager.Instance.RegisterScript("MyScript_123", myScript, "MyGem");
// Subscribe to reload events
HotReloadManager.Instance.ScriptReloading += (sender, args) =>
{
if (args.IsBeforeReload)
SaveCustomState();
};
HotReloadManager.Instance.ScriptReloaded += (sender, args) =>
{
RestoreCustomState();
};
// Get current reload generation
int gen = HotReloadManager.Instance.ReloadGeneration;The generated C++ code includes callbacks for native integration:
#include "MyGem_HotReload.g.h"
// Set up callbacks
MyGem::Generated::HotReloadCallbacks::SetBeforeUnloadCallback(
[](const AZStd::string& gemName) {
// Save native state
});
MyGem::Generated::HotReloadCallbacks::SetAfterLoadCallback(
[](const AZStd::string& gemName) {
// Restore native state
});- Assets/Scripts/O3DE.Core/HotReload/HotReloadManager.cs
- Generated:
{GemName}_HotReload.g.h
The generator creates extension methods for a fluent/builder API pattern.
-
SetX()methods getWithX()fluent wrappers - Properties get
WithPropertyName()setters - Void methods with common prefixes get
*Fluent()wrappers
// Traditional API
var transform = new Transform();
transform.SetPosition(new Vector3(0, 0, 0));
transform.SetRotation(Quaternion.Identity);
transform.SetScale(new Vector3(1, 1, 1));
// Fluent API
var transform = new Transform()
.WithPosition(new Vector3(0, 0, 0))
.WithRotation(Quaternion.Identity)
.WithScale(new Vector3(1, 1, 1));In binding_config.json:
{
"global": {
"generateExtensionMethods": true
}
}- Generation/ExtensionMethodGenerator.cs
- Generated:
FluentExtensions.g.csper gem
C++ default parameter values are now converted to C# optional parameters.
| C++ | C# |
|---|---|
nullptr |
null |
true/false
|
true/false
|
1.0f |
1.0f |
MyEnum::Value |
MyEnum.Value |
AZ::Vector3(0,0,0) |
new Vector3(0,0,0) |
{} |
default |
C++ Header:
void SetPosition(const AZ::Vector3& pos = AZ::Vector3::Zero);
void SetEnabled(bool enabled = true);
void SetName(const char* name = nullptr);Generated C#:
public void SetPosition(Vector3 pos = default);
public void SetEnabled(bool enabled = true);
public void SetName(string? name = null);An MSBuild task enables design-time binding generation for IntelliSense support.
Reference the NuGet package in your .csproj:
<PackageReference Include="O3DESharp.BindingGenerator.Tasks" Version="1.0.0" />Or set the path manually:
<PropertyGroup>
<O3DEBindingGeneratorTasksPath>path/to/O3DESharp.BindingGenerator.Tasks.targets</O3DEBindingGeneratorTasksPath>
</PropertyGroup>
<Import Project="$(O3DEBindingGeneratorTasksPath)" />| Property | Default | Description |
|---|---|---|
O3DEProjectPath |
Auto | Path to project.json or gem.json |
O3DEBindingConfig |
Auto | Path to binding_config.json |
O3DEGeneratorPath |
Auto | Path to generator executable |
O3DEGenerateBindings |
true |
Enable build-time generation |
O3DEDesignTimeGenerate |
true |
Enable design-time generation |
O3DEIncremental |
true |
Use incremental builds |
O3DEForceRegen |
false |
Force full regeneration |
O3DEVerbose |
false |
Verbose output |
O3DECleanBindings |
false |
Clean generated files on dotnet clean
|
<ItemGroup>
<O3DEGems Include="MyGem" />
<O3DEGems Include="AnotherGem" />
</ItemGroup>- O3DESharp.BindingGenerator.Tasks.csproj
- GenerateBindingsTask.cs
- build/O3DESharp.BindingGenerator.Tasks.targets
- build/O3DESharp.BindingGenerator.Tasks.props
Build all components:
# Build the binding generator
dotnet build Code/Tools/BindingGenerator/O3DESharp.BindingGenerator/O3DESharp.BindingGenerator.csproj -c Release
# Build the MSBuild tasks package
dotnet pack Code/Tools/BindingGenerator/O3DESharp.BindingGenerator.Tasks/O3DESharp.BindingGenerator.Tasks.csproj -c Release
# Build O3DE.Core with hot reload support
dotnet build Assets/Scripts/O3DE.Core/O3DE.Core.csproj -c ReleaseOr use the solution:
dotnet build O3DESharp.sln -c Release- Initial implementation of all advanced features
- Incremental build with SHA256 hashing
- Runtime metadata generation (C# and JSON)
- Hot reload support with state preservation
- Fluent API extension methods
- Default parameter value conversion
- MSBuild task for design-time generation