# 🛠️ Build Guide

If you want to build the GDExtension or a custom-module Godot Engine yourself, or to develop the plugin in parallel with SpriteStudio-SDK, follow these steps. They also cover using a changed player in a project and checking it in Godot; how the player is put together, and why, is on [How the Player Is Put Together](<https://cri-middleware.github.io/SSPlayerForGodot/development/architecture/index.md>).

## Overview

The flow for producing Godot binaries from this repository is as follows:

1. **Prepare `libssruntime`** — Obtain the SpriteStudio-SDK release artifacts and place them under `ss_player/runtime/`.
2. Depending on how you want to consume the plugin, run **2-A. Build the GDExtension** or **2-B. Build the Custom-Module Godot Engine** to link the runtime above and produce Godot binaries.

## Get the Source

Clone this repository, and clone Godot Engine / godot-cpp depending on your build target.

```bash
git clone https://github.com/cri-middleware/SSPlayerForGodot.git
cd SSPlayerForGodot
git submodule update --init ss_player/flatbuffers
git clone https://github.com/godotengine/godot.git -b "$(cat scripts/GODOT_VERSION.txt)"
git clone https://github.com/godotengine/godot-cpp.git -b master
```

The `godot` directory is required when building a custom-module Godot Engine. The `godot-cpp` directory is required when building the GDExtension.

> [!NOTE]
>
> For typical builds that consume SDK release artifacts, the `ss_player/SpriteStudio-SDK/` submodule does **not** need to be initialized, but `ss_player/flatbuffers/` does: every build includes its headers, which is why the block above initializes it. To develop SpriteStudio-SDK itself, or to run `deploy-examples` and the tests (see CONTRIBUTING), follow [For SpriteStudio-SDK Developers](<#for-spritestudio-sdk-developers>) below and initialize the submodule with `git submodule update --init --recursive`.

## Build Environment Setup

For build tools (compiler, Python, SCons, etc.) on each platform, follow the official Godot compilation guides. The build scripts (`build.sh`, `build-extension.sh`, `build-runtime.sh` and the `release-*.sh` ones) run under zsh, so zsh is needed as well; the other scripts use bash:

- [Windows](<https://docs.godotengine.org/en/stable/engine_details/development/compiling/compiling_for_windows.html>)
- [macOS](<https://docs.godotengine.org/en/stable/engine_details/development/compiling/compiling_for_macos.html>)
- [Linux](<https://docs.godotengine.org/en/stable/engine_details/development/compiling/compiling_for_linuxbsd.html>)
- [Android](<https://docs.godotengine.org/en/stable/engine_details/development/compiling/compiling_for_android.html>)
- [iOS](<https://docs.godotengine.org/en/stable/engine_details/development/compiling/compiling_for_ios.html>)
- [Web](<https://docs.godotengine.org/en/stable/engine_details/development/compiling/compiling_for_web.html>)

### Notes

#### Godot third-party build dependencies (AccessKit / ANGLE)

Godot 4.7 links two prebuilt SDKs that are not part of the engine source tree: **AccessKit** (screen reader support) and **ANGLE** (the OpenGL ES rendering driver). If they are missing, `scons` prints a warning and silently disables those drivers, producing binaries that lack features the official Godot builds ship with.

`build.sh` / `build.ps1` download them on the first desktop build (using the installers in the `godot/` checkout, so the versions always match the engine revision) into `godot/bin/build_deps/` — or `%LOCALAPPDATA%\Godot\build_deps` on Windows. Pass `deps=no` to skip the download and build without those drivers:

```sh
./scripts/build.sh deps=no
```

The mobile and web platforms do not use either dependency, so nothing is downloaded for them.

#### Building Universal Binaries on macOS

The `molten-vk` package distributed via Homebrew only provides binaries for the host architecture, so linking fails when building with `arch=universal`. Install the universal-capable [Vulkan SDK for MoltenVK](<https://vulkan.lunarg.com/sdk/home>) instead.

## 1\. Prepare libssruntime

Fetches and extracts the SDK package version pinned in `scripts/SDK_VERSION.txt`.

**macOS / Linux**

```sh
./scripts/download-sdk.sh
```

**Windows (PowerShell)**

```powershell
.\scripts\download-sdk.ps1
```

> `libssconverter` (the `.sspj` → `.ssab` converter library) is bundled only for desktop platforms. The iOS / Android / Web `libssruntime` packages do not include it.

To build `libssruntime` from the SpriteStudio-SDK source yourself, see [For SpriteStudio-SDK Developers](<#for-spritestudio-sdk-developers>).

## 2-A. Build the GDExtension

Requires `godot-cpp` to be cloned at the `master` branch.

**macOS / Linux**

```sh
./scripts/build-extension.sh
```

**Windows (PowerShell)**

```powershell
$env:PYTHONUTF8=1
.\scripts\build-extension.ps1
```

Output is placed under `bin/<platform>/`, and the GDExtension package (including `misc/spritestudio.gdextension`) is installed into `examples/dev_gdextension/addons/spritestudio/`, and copied to `examples/overall_gdextension/` and `test_gdextension/`.

## 2-B. Build the Custom-Module Godot Engine

Requires `godot` to be cloned at the `4.7` branch. `build.sh` / `build.ps1` invoke `scons` with `custom_modules=../ss_player`.

**macOS / Linux**

```sh
./scripts/build.sh
```

**Windows (PowerShell)**

```powershell
$env:PYTHONUTF8=1
.\scripts\build.ps1
```

Output is placed under `godot/bin/`. On macOS, `godot/Godot.app` is also created.

## Release Builds

Per-platform scripts under `scripts/` build `editor` / `template_debug` / `template_release` in one shot (iOS, Android and Web: the two templates only). Internally they invoke `build.sh` / `build-extension.sh` repeatedly with different `target` values. These scripts do **not** fetch or build `libssruntime`, so [1\. Prepare libssruntime](<#1-prepare-libssruntime>) must be completed first.

### GDExtension

| Platform | Script | Notes |
| --- | --- | --- |
| Windows | `.\scripts\release-gdextension-windows.ps1` | `arch` = host |
| macOS | `./scripts/release-gdextension-macos.sh` | Fixed at `arch=universal` |
| Linux | `./scripts/release-gdextension-linux.sh` | `arch` = host |
| iOS | `./scripts/release-gdextension-ios.sh` | Only `template_debug` / `template_release` |
| Android | `./scripts/release-gdextension-android.sh` | Three architectures: `arm32` / `arm64` / `x86_64` |
| Web | `./scripts/release-gdextension-web.sh` | `wasm32`, `threads=no` only |

### Custom-module Godot Engine

| Platform | Script | Notes |
| --- | --- | --- |
| Windows | `.\scripts\release-windows.ps1` | `arch` = host |
| macOS | `./scripts/release-macos.sh` | Fixed at `arch=universal` |
| iOS | `./scripts/release-ios.sh` | `arch=arm64` (device) and `arch=universal` (simulator) |
| Android | `./scripts/release-android.sh` | Three architectures: `arm32` / `arm64` / `x86_64` |
| Web | `./scripts/release-web.sh` | `wasm32`, `threads=no`; only `template_debug` / `template_release` |

> No batch release script is provided for the Linux custom module. Invoke `./scripts/build.sh platform=linux target=...` directly for each of `editor` / `template_debug` / `template_release`.

## Using a Changed Player

`scripts/build-extension.sh` builds the GDExtension for the host and installs it, with `misc/spritestudio.gdextension`, the icons and the licenses, into `examples/dev_gdextension/addons/spritestudio/`, and copies the binaries and icons to `examples/overall_gdextension/` and `test_gdextension/`. Copy that folder to your project's `addons/spritestudio/` and reopen the project. It holds the host platform's `editor` build only (`build-extension.sh` defaults to `target=editor`; add `target=template_debug` / `template_release` for exports): other platforms come from the per-platform scripts in [Release Builds](<#release-builds>), and the release zip, `scripts/build-release.sh`, is assembled from CI's artifacts of every platform.

For the custom module, the engine is the player: `scripts/build.sh` builds an editor with it, and the release scripts build the export templates that `scripts/install-template.sh` installs.

## Debugging the Custom Module

If you want to debug the C++ code (`ss_player/`) of the plugin embedded as a custom module, follow these steps:

1. **Build with Debug Symbols** Godot builds carry no debug symbols by default, `target=editor` and `target=template_debug` included. Build with `debug_symbols=yes` (`./scripts/build.sh debug_symbols=yes`, or the `.ps1` on Windows). The binaries are:
2. **macOS:** `godot/Godot.app/Contents/MacOS/Godot`
3. **Windows:** `godot/bin/godot.windows.editor.x86_64.exe` etc.
4. **Linux:** `godot/bin/godot.linuxbsd.editor.x86_64` etc.
5. **Attach Debugger and Launch Arguments** Specify the above binary as the launch program in your debugger (e.g., VSCode, Visual Studio, Xcode, LLDB/GDB). By passing the path to the target project as an argument (e.g., `--path examples/dev_module`), you can open the project directly without the project manager screen and start debugging.

**VSCode (`launch.json`) Example (macOS / LLDB):**

```json
{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "Debug Godot Custom Module",
            "type": "lldb",
            "request": "launch",
            "program": "${workspaceFolder}/godot/Godot.app/Contents/MacOS/Godot",
            "args": [
                "--path",
                "${workspaceFolder}/examples/dev_module"
            ],
            "cwd": "${workspaceFolder}"
        }
    ]
}
```

## Export Testing and Debugging

To verify and debug whether the custom module or GDExtension works correctly in the exported application, using the headless export from the CLI is convenient.

> [!IMPORTANT]
>
> Common export pitfalls (all platforms):
>
> - **Build the exact `target` you export with.** An `editor` build alone is not enough — `--export-debug` needs the `template_debug` library and `--export-release` needs `template_release`. If those were never built, the export still "succeeds" but ships an empty/missing extension library (on macOS this surfaces as a `CodeSign: Invalid binary format` error on the embedded framework).
> - **The extension architecture is bounded by the runtime slices you have.** The GDExtension links `libssruntime` from `ss_player/runtime/libs/<platform>/`; you can only build the architectures present there. For example, with an `arm64`-only macOS runtime you cannot produce a `universal` / `x86_64` extension — set the preset's `binary_format/architecture` to match (e.g. `arm64`). The engine template can still be `universal`; a single-arch extension just won't load on the missing arch.
> - **Enable ETC2/ASTC for `universal` / `arm64` / mobile exports.** Set `rendering/textures/vram_compression/import_etc2_astc=true` in the project (`project.godot` → `[rendering]`), otherwise the export aborts with *"Cannot export … with the ETC2/ASTC texture format disabled."*
> - **Export templates must match the editor version.** Setting `custom_template/debug` / `custom_template/release` bypasses the version check (this is how a template built from the `godot/` checkout can be reused). Set **both** debug and release paths even for a debug-only export — Godot validates both and otherwise reports the release template as missing.

The following is the flow for building/installing templates and exporting a sample project. (The example below uses macOS)

1. **Build the runtime and templates** Prepare `libssruntime` beforehand, then run the release script for the target platform.

   ```bash
   # Prepare the runtime in release build (if necessary)
   ./scripts/build-runtime.sh build=release platform=macos arch=universal

   # Build the export templates
   ./scripts/release-macos.sh
   ```
2. **Install templates** Install the built templates into the local directory recognized by Godot. **macOS / Linux:**

   ```bash
   ./scripts/install-template.sh macos
   ```

   **Windows (PowerShell):**

   ```powershell
   .\scripts\install-template.ps1 windows
   ```
3. **Run export from CLI** Use the built Godot editor (in headless mode) to invoke the export process directly from the command line. **macOS / Linux:**

   ```bash
   # Example: Export the dev_module project for macOS (outputs directly as .app)
   ./godot/Godot.app/Contents/MacOS/Godot --path ./examples/dev_module/ --headless --export-debug "macOS" output.app
   ```

   **Windows (PowerShell):**

   ```powershell
   .\godot\bin\godot.windows.editor.x86_64.exe --path .\examples\dev_module\ --headless --export-debug "Windows Desktop" output.exe
   ```

   > **Note:** To run the export, the target project's `export_presets.cfg` must contain the preset for the specified platform name (e.g., `"macOS"`), and required identifiers (such as Bundle ID) must be properly configured. No sample ships `export_presets.cfg` (it is gitignored): create the preset in the editor first (**Project → Export**). The package name / bundle ID below (`com.crimw.devmodule`, `com.crimw.devgdext`) are what the commands assume; use the one you set.

### Web Platform Export and Testing

Exporting for the Web produces multiple files (e.g., `.html`, `.wasm`, `.pck`), so create a dedicated directory for the export. Additionally, a local server is required to bypass browser security restrictions.

```bash
# 1. Create an output directory and export for Web
mkdir -p build_web
./godot/Godot.app/Contents/MacOS/Godot --path ./examples/dev_module/ --headless --export-debug "Web" ../../build_web/index.html

# 2. Start a local HTTP server
cd build_web
python3 -m http.server 8000
```

After starting the server, access `http://localhost:8000` in your browser to verify it works. (Since this plugin operates with `nothread` on the Web, it can be launched with a simple HTTP server without requiring special CORS headers.)

#### GDExtension on the Web (Extensions Support / `dlink`)

The official Godot Web export templates do **not** support GDExtension libraries. If you export the **GDExtension** build variant for the Web with a stock template, the page fails at startup with:

> GDExtension libraries are not supported by this engine version. Enable "Extensions Support" for your export preset and/or build your custom template with "dlink\_enabled=yes".

To load a GDExtension on the Web, you need an engine template built with dynamic linking enabled (`dlink_enabled=yes`). Build one from the `godot/` checkout, matching the `threads` mode of your extension (this plugin ships `nothread`, so use `threads=no`):

```bash
# Build dlink-enabled Web templates from source (nothreads)
cd godot
scons platform=web target=template_debug   dlink_enabled=yes threads=no
scons platform=web target=template_release dlink_enabled=yes threads=no
# → godot/bin/godot.web.template_debug.wasm32.nothreads.dlink.zip
# → godot/bin/godot.web.template_release.wasm32.nothreads.dlink.zip
```

Then install the built templates so Godot can resolve them by name:

```bash
./scripts/install-template.sh web
# installs → <export_templates>/<version>/web_dlink_nothreads_debug.zip
#                                          web_dlink_nothreads_release.zip
```

Once these are installed, exporting only requires turning on **Extensions Support** in the Web preset — Godot auto-selects the matching `..._dlink_...` template by name, so no `custom_template` is needed. The preset side (from a plugin user's perspective) is covered in [Exporting Your Project → Web](<https://cri-middleware.github.io/SSPlayerForGodot/workflow/export/index.md#web>).

> If you would rather not install them into Godot's templates folder, you can instead point `custom_template/debug` / `custom_template/release` in the `Web` preset directly at the built `*.dlink.zip` files.

A dlink template splits the engine into a small main module plus a large `godot.side.wasm`; after export you will see a corresponding `index.side.wasm` alongside `index.wasm`, which confirms the dlink template was used.

> [!NOTE]
>
> `dlink` / *Extensions Support* is required only for the **GDExtension** build variant. The **custom module** variant compiles the plugin into the engine, so its Web template is the ordinary (non-`dlink`) `web_nothreads_{debug,release}.zip` produced by `release-web.sh` (via `build.sh`) and installed the same way — with no `dlink_enabled` and no *Extensions Support* in the preset.

### Android Platform Export and Testing

Android export templates are template APKs packaged by the engine's Gradle project. Unlike the desktop platforms, the template build therefore has three stages (runtime → per-ABI engine libraries → Gradle packaging) before `install-template.sh`.

**Prerequisites** - Android SDK and NDK, with `cargo-ndk` and the Rust Android targets installed (`aarch64-linux-android`, `armv7-linux-androideabi`, `x86_64-linux-android`). - Export the SDK/NDK paths so the build scripts can find them (adjust to your environment):

```bash
export ANDROID_HOME="$HOME/Library/Android/sdk"
export ANDROID_NDK_ROOT="$ANDROID_HOME/ndk/<ndk-version>"
```

\- With `ANDROID_HOME` set, godot-cpp and the engine build take the NDK from `$ANDROID_HOME/ndk/<version>` and not from `ANDROID_NDK_ROOT`: install the version `NDK_VERSION` names at the top of `scripts/release-gdextension-android.sh` for the GDExtension, and the one Godot names (`get_ndk_version()` in `godot/platform/android/detect.py`) for the engine. - Once, in `godot/`: `python misc/scripts/install_swappy_android.py` (without it `scons` warns and builds without frame pacing). - In the Godot editor settings, configure the Android SDK path and a debug keystore (`export/android/android_sdk_path`, `export/android/debug_keystore`, `export/android/debug_keystore_pass`).

1. **Build the runtime and templates** Build the Rust runtime once, then build the engine shared library for each ABI/target, and package them into the template APKs with Gradle.

   ```bash
   # Rust runtime (a single release build is reused by both template targets)
   ./scripts/build-runtime.sh platform=android build=release
   # Alternatively, fetch the prebuilt runtime for all platforms instead of building it:
   #   ./scripts/download-sdk.sh

   # Engine .so per ABI. arch: arm64 / arm32 / x86_64, target: template_release / template_debug
   ./scripts/build.sh platform=android arch=arm64  target=template_release
   ./scripts/build.sh platform=android arch=arm32  target=template_release
   ./scripts/build.sh platform=android arch=x86_64 target=template_release
   ./scripts/build.sh platform=android arch=arm64  target=template_debug   # add other ABIs as needed

   # Package into android_release.apk / android_debug.apk / android_source.zip
   (cd godot/platform/android/java && ./gradlew generateGodotTemplates)
   ```

   > The `arch` values follow Godot's names (`arm64`, `arm32`, `x86_64`, `x86_32`), while the runtime libraries are placed under the matching Android ABI directories (`arm64-v8a`, `armeabi-v7a`, `x86_64`, `x86`). You only need the ABI of the device/emulator you intend to run on.
2. **Install templates**

   ```bash
   ./scripts/install-template.sh android
   ```
3. **Run export from CLI**

   ```bash
   mkdir -p bin_export
   ./godot/Godot.app/Contents/MacOS/Godot --path ./examples/dev_module/ --headless --export-debug "Android" "$(pwd)/bin_export/dev_module_debug.apk"
   ```

   > **Note:** Android export requires ETC2/ASTC texture import to be enabled. Otherwise the export aborts with a configuration error whose message is empty. Set `rendering/textures/vram_compression/import_etc2_astc=true` in the project settings (already enabled in `examples/dev_module`).
4. **Install and run on a device / emulator**

   ```bash
   adb install -r bin_export/dev_module_debug.apk
   adb shell am start -n com.crimw.devmodule/com.godot.game.GodotAppLauncher
   adb logcat -s godot        # check the engine log / errors
   adb exec-out screencap -p > screen.png   # capture the rendered frame
   ```

   `dev_module` is an empty scratch project (its scene is a bare `Node2D`, and `ssab_generated/` is not committed): to see a character, first convert a `.sspj` with the SS Importer dock and add a `SpriteStudioPlayer2D` with that pack and `autoplay` on.

### iOS Platform Export and Testing

iOS export requires **macOS with Xcode**. Godot generates an **Xcode project** (not a ready-to-run app) and then auto-runs `xcodebuild archive` for a device, which needs an Apple Developer account — so an **App Store Team ID must be set in the preset**, and the device-archive step fails without valid signing. For a quick, unsigned check, build the generated project for the **iOS Simulator** yourself.

> [!IMPORTANT]
>
> **Self-built iOS templates do not bundle MoltenVK.** Godot's iOS engine is built with Vulkan, so the app binary hard-links `@rpath/MoltenVK.framework/MoltenVK` (confirm with `otool -L`). This is a property of the *engine build*, not the project's renderer — a GL Compatibility project links it too. The **official** Godot iOS templates ship `MoltenVK.xcframework`; the template produced by `release-ios.sh` does **not**. When testing a self-built template you must supply it yourself, or the app crashes at launch with `Library not loaded: @rpath/MoltenVK.framework/MoltenVK`.

Simulator smoke-test of a self-built template (custom module shown; the GDExtension flow is identical with `dev_gdextension`):

```bash
# 1. Export the Xcode project (Godot's device-archive step will fail on signing — that's expected)
mkdir -p bin_export/ios
./godot/Godot.app/Contents/MacOS/Godot --path ./examples/dev_module/ --headless \
    --export-debug "iOS" "$(pwd)/bin_export/ios/dev_module.xcodeproj" || true

# 2. Place MoltenVK where the Xcode project expects it (e.g. from the Vulkan SDK)
MVK="$HOME/VulkanSDK/<ver>/iOS/lib/MoltenVK.xcframework"
cp -R "$MVK" bin_export/ios/MoltenVK.xcframework

# 3. Build for the Simulator, unsigned
cd bin_export/ios
xcodebuild -project dev_module.xcodeproj -scheme dev_module \
    -sdk iphonesimulator -configuration Debug -derivedDataPath ./DerivedData \
    CODE_SIGNING_ALLOWED=NO CODE_SIGNING_REQUIRED=NO build
APP="DerivedData/Build/Products/Debug-iphonesimulator/dev_module.app"

# 4. Embed MoltenVK into the app and ad-hoc re-sign (the simulator rejects the SDK's own signature)
cp -R "$MVK/ios-arm64_x86_64-simulator/MoltenVK.framework" "$APP/Frameworks/"
codesign --force --sign - "$APP/Frameworks/MoltenVK.framework"
codesign --force --sign - "$APP"

# 5. Boot a simulator, install, launch, screenshot
DEV=$(xcrun simctl list devices available | grep -m1 -oE '\([0-9A-F-]{36}\)' | tr -d '()')
xcrun simctl boot "$DEV" && xcrun simctl install "$DEV" "$APP"
xcrun simctl launch "$DEV" com.crimw.devmodule
xcrun simctl io "$DEV" screenshot screen.png
```

> **Note:** The manual steps above are only needed for **self-built** templates — end users on the official Godot editor and official export templates are unaffected.

### GDExtension Export and Testing

For GDExtensions (e.g., `dev_gdextension`), **rebuilding the engine itself or installing custom templates is unnecessary**. You can export as-is using the standard Godot editor and official export templates distributed by Godot.

1. **Release build of the GDExtension plugin** Run the build script for the target platform beforehand to output the libraries (e.g., `.so`, `.xcframework`, `.dll`) into the project's `addons/` directory. **macOS / Linux:**

   ```bash
   ./scripts/release-gdextension-macos.sh
   ```

   **Windows (PowerShell):**

   ```powershell
   .\scripts\release-gdextension-windows.ps1
   ```
2. **Run export from CLI** Export the project using the official Godot binary (or your own Godot command). **macOS / Linux:**

   ```bash
   # * Here, "godot" refers to the official Godot editor executable in your path.
   godot --path ./examples/dev_gdextension/ --headless --export-debug "macOS" output.app
   ```

   **Windows (PowerShell):**

   ```powershell
   # * "godot.exe" refers to the official Godot executable.
   godot.exe --path .\examples\dev_gdextension\ --headless --export-debug "Windows Desktop" output.exe
   ```

   > During export, Godot will automatically bundle the plugin files (`.so`, `.framework`, `.dll`, etc.) into the exported artifacts.

**Android note:** Android needs a few extra steps beyond the desktop flow above: - Build the Android plugin libraries with `./scripts/release-gdextension-android.sh` (requires the Android SDK/NDK, `cargo-ndk`, the Rust Android targets, and the Android runtime — build it with `./scripts/build-runtime.sh platform=android build=release` or fetch the prebuilt one with `./scripts/download-sdk.sh`). The `arch` values are Godot's names (`arm64`, `arm32`, `x86_64`), while the runtime is linked from the matching Android ABI directory (`arm64-v8a`, `armeabi-v7a`, `x86_64`). - Also build the **host** plugin (e.g. `./scripts/release-gdextension-macos.sh`). During export the `.ssab` resources are loaded on the host machine, so without a working host library the export drops them with a `Failed loading resource` error and the resulting APK ships without animation data. - Install the official **Android** export templates for the official Godot version you are using (via *Manage Export Templates* in the editor, or by placing the `.tpz` contents under `.../export_templates/<version>/`). - Enable `rendering/textures/vram_compression/import_etc2_astc=true` in the project settings (already set in `examples/dev_gdextension`); otherwise the export aborts with a configuration error whose message is empty. - Then export and run on a device / emulator:

```bash
mkdir -p bin_export
godot --path ./examples/dev_gdextension/ --headless --export-debug "Android" "$(pwd)/bin_export/dev_gdextension_debug.apk"
adb install -r bin_export/dev_gdextension_debug.apk
adb shell am start -n com.crimw.devgdext/com.godot.game.GodotAppLauncher
adb logcat -s godot
```

## Debugging the GDExtension

You can debug the C++ code for GDExtensions using almost the same steps as a custom module. The only difference is that the launch program is the "official Godot editor".

1. **Build the GDExtension with debug symbols** The build scripts (like `build-extension.sh`) default to `target=editor` and, as godot-cpp does, leave debug symbols out. Pass `debug_symbols=yes` (`./scripts/build-extension.sh debug_symbols=yes`, or the `.ps1` on Windows) so the output libraries (`.dll`, `.so`, or the `.framework` on macOS) are built with them.
2. **Attach Debugger and Launch Arguments** Specify the **official Godot binary** as the launch program in your debugger (e.g., VSCode, Visual Studio), and pass the project path as an argument (`--path examples/dev_gdextension`). The breakpoint will be hit once Godot dynamically loads the plugin at startup.

**VSCode (`launch.json`) Examples:**

**macOS / Linux (LLDB):**

```json
{
    "name": "Debug GDExtension (macOS)",
    "type": "lldb",
    "request": "launch",
    "program": "/Applications/Godot.app/Contents/MacOS/Godot", // Path to official binary
    "args": [ "--path", "${workspaceFolder}/examples/dev_gdextension" ],
    "cwd": "${workspaceFolder}"
}
```

**Windows (Visual Studio Debugger):**

```json
{
    "name": "Debug GDExtension (Windows)",
    "type": "cppvsdbg",
    "request": "launch",
    "program": "C:\\path\\to\\Godot_v4.x-stable_win64.exe", // Path to official binary
    "args": [ "--path", "${workspaceFolder}\\examples\\dev_gdextension" ],
    "cwd": "${workspaceFolder}"
}
```

## Checking Against the Real Host

`scripts/run-tests.sh` runs the GDExtension build headless (CONTRIBUTING has its rules). Two things it cannot see: pixels, because `--headless` installs a dummy rasteriser, and anything wired on entering the tree, because the suite runs every case before its root enters one — `SpriteStudioPartAttachment2D` and sound are two. CI compiles the GDExtension for Linux and the Web on every pull request, and every platform's GDExtension plus the custom module on the weekly run and the release PR; it runs no tests, so run the suite yourself. [Export Testing and Debugging](<#export-testing-and-debugging>) covers each export platform, and the debugging sections cover attaching a debugger.

### Where Godot's labels come from

The guides name the editor's menus and docks as Godot shows them. The English strings are in the engine source (`godot/editor/`), and the Japanese ones in `godot/editor/translations/editor/ja.po`. The plugin translates its own strings, but the editor does not show them: it turns off the main translation domain and translates its own UI from the `godot.editor` domain, so the dock and the inspector read in English in a Japanese editor, and the Japanese pages name their buttons in English.

### Pixels and the tree, from a script

A `SceneTree` script run with `--script` draws for real and enters the tree:

```bash
rsync -a --exclude 'ssab_generated/*' examples/dev_gdextension/ <scratch>/proj/
rsync -a examples/dev_gdextension/ssab_generated/<pack> <scratch>/proj/ssab_generated/
cd <scratch>/proj && <godot> --path . --script res://probe.gd
```

Copying the project with its `.godot/` lets `load()` work without a re-import.

- Add nodes after `await process_frame`; the tree is not up straight after `_initialize`.
- `await RenderingServer.frame_post_draw`, then `get_root().get_texture().get_image().save_png(…)`, or read pixels with `Image.get_pixel`.
- Set the player's `animation_process_mode` to `ANIMATION_PROCESS_MANUAL` and assign `frame_no`; assignment always redraws, while `advance(0.0)` on the same frame may not.
- An effect whose texture cannot be read is not drawn. To compare an SDK test project, put the `.ssab` beside the original images in a scratch project and import it once with `<godot> --headless --path <proj> --import`.
- `set_part_visibility_override` on all but one part shows what that part draws.
- Compare renderers with `--rendering-method forward_plus`: `dev_gdextension` defaults to Compatibility, the projects derived from `test_gdextension` to Forward+.
- Check a light mask with a `PointLight2D`. A `DirectionalLight2D` lights a `light_mask = 2` `Sprite2D` whatever its `range_item_cull_mask`, so keep a `Sprite2D` beside the player as the control.

### The editor, from a script

A scratch project with `addons/spritestudio` (without its `.uid` files), a `.ssab` and an `@tool` EditorPlugin enabled in `project.godot` (`[editor_plugins] enabled=`) can drive the plugin's editor UI. Run `--headless --editor --quit` once first, to write `extension_list.cfg`.

- **Playback panel:** `EditorInterface.open_scene_from_path`, `edit_node`, then find the panel under `get_base_control()` with `find_child` and press its buttons. Undo and redo go through `get_undo_redo().get_history_undo_redo(get_object_history_id(node))`.
- **Import dock:** find the dock the same way and call the handler its recent-file list calls.
- **Dropping files:** the dock's drop handler checks that the mouse is over the dock, and headless there is no OS cursor. Put an `InputEventMouseMotion` at the dock's centre through `Input.parse_input_event`, `Input.flush_buffered_events()`, then `get_tree().root.files_dropped.emit([<dir>])`. Dialogs are the visible `AcceptDialog`s, and a button is pressed with `pressed.emit()`.
- **FileSystem menu:** `EditorInterface.select_file(<path>)`, then emit `item_mouse_selected` with the right button on the dock's first `Tree`; the dock's `PopupMenu` fills, and an item is pressed with `id_pressed.emit(<id>)`. The plugin's items in the 2000s come through `_get_menu_options`, those in the 3000s through `_popup_menu`, so the ID says which path ran.
- **The editor in another language, without touching your settings:** copy `Godot.app` (`cp -Rc` on APFS) and put an empty `._sc_` beside the copy. That makes it self-contained, with its settings in `editor_data/editor_settings-4.7.tres` next to it; set `interface/editor/localization/editor_language` there. Run it without `--headless` and take the screenshot from the probe; `TabContainer.get_tab_title()` returns the untranslated text.

### When it crashes

The official editor cannot be attached to by lldb (hardened runtime). Build the engine with symbols — `scons platform=macos target=editor dev_build=yes scu_build=yes arch=arm64` in `godot/`, which writes `bin/godot.macos.editor.dev.arm64` beside the module build — run it with `--disable-crash-handler`, and use `lldb --batch -o run -k "bt all"`. Build the extension with `build-extension.sh debug_symbols=yes`; without symbols, `atos` cannot name a frame in `libSSGodot`.

Two crashes are not the player's. The suite's first import pass, straight after a build or in a new clone, can crash in shutdown with `Parameter "singleton" is null` and no extension frame in the backtrace; a second run passes. And `godot/bin/`'s editor is the module build: loading the GDExtension into it registers every class twice ("already registered") — use `godot-bin/`, from `scripts/fetch-godot.sh`, for the GDExtension.

### Trying an SDK change

`build-runtime` builds from the submodule, so point the submodule at the SDK branch — a local one needs no push (`git remote add local-sdk <SDK checkout>` inside `ss_player/SpriteStudio-SDK`, then fetch and check out the branch) — and run `scripts/build-runtime.sh`. Then rebuild: `build-extension.sh` for the GDExtension, `build.sh` for the module, or the module keeps the old `libssruntime.a`. Put the submodule back when you are done.

## For SpriteStudio-SDK Developers

> The sections below are required **only when developing/customizing SpriteStudio-SDK itself in parallel with the Godot side**, except [Deploying the sample project assets](<#deploying-the-sample-project-assets>), which everyone who runs the samples or the tests needs. General Godot builders using the SpriteStudio-SDK release artifacts can skip the rest.

### Additional Requirements

For setting up the environment to build `libssruntime` yourself (Rust toolchain, etc.), refer to the [SpriteStudio-SDK README](<https://github.com/cri-middleware/SpriteStudio-SDK/blob/HEAD/README.md#️-for-sdk-developers>).

If you also need to regenerate FlatBuffers headers, install the `flatc` release that matches the `ss_player/flatbuffers` submodule: the generated headers assert that version at compile time (`FLATBUFFERS_VERSION_*` at the top of `ss_player/format/ssab.h`).

### Building libssruntime from source

Requires the SpriteStudio-SDK submodule (`ss_player/SpriteStudio-SDK/`) to be initialized. If it is not initialized yet, run:

```bash
git submodule update --init --recursive
```

Then run the script below to build the Rust runtime/converter; the artifacts are placed under `ss_player/runtime/` automatically.

**macOS / Linux**

```sh
./scripts/build-runtime.sh [platform=<platform>] [arch=<arch>] [build=<build>] [ios_simulator=<yes|no>]
```

**Windows (PowerShell)**

```powershell
.\scripts\build-runtime.ps1 [platform=<platform>] [arch=<arch>] [build=<build>] [ios_simulator=<yes|no>]
```

| Option | Values | Default |
| --- | --- | --- |
| `platform` | `windows`, `macos`, `linux`, `android`, `ios`, `web` | Host OS |
| `arch` | `x86_64`, `arm64`, `universal`, `wasm32`, etc. | Host Arch |
| `build` | `debug`, `release` | `debug` |
| `ios_simulator` | `yes`, `no` | `no` |

### Regenerating FlatBuffers headers

When `.fbs` files in SpriteStudio-SDK have changed, regenerate the headers under `ss_player/format/` (requires `flatc`).

**macOS / Linux**

```sh
./scripts/generate-fbs-code.sh
```

**Windows (PowerShell)**

```powershell
.\scripts\generate-fbs-code.ps1
```

### Deploying the sample project assets

The sample projects under `examples/` load `.ssab` assets converted from the SpriteStudio-SDK test projects. Regenerate them whenever an `ssab_generated/` directory is missing or the SDK version has changed. Opening a sample does not convert anything by itself. Each sample carries a `.ssplayer_sources.cfg` that names its output folder and its source `.sspj`, so dropping that `.sspj` onto the SS Importer dock in the Godot Editor regenerates the assets there; the script below does the same thing headlessly. It converts with `ssconverter-cli` built from the submodule, so unlike the dock it needs a Rust toolchain.

**macOS / Linux**

```sh
./scripts/deploy-examples.sh
```

**Windows (PowerShell)**

```powershell
.\scripts\deploy-examples.ps1
```

> The `examples/dev_*` projects are excluded: they are developer-only scratch projects, so both their sources config and `ssab_generated/` are gitignored and set up by hand in the editor.

### Player Porting Guide

The runtime semantics a Player must honour are documented in the SpriteStudio-SDK [Player Porting Guide](<https://github.com/cri-middleware/SpriteStudio-SDK/blob/HEAD/libs/ssruntime/docs/README.md>) (`ss_player/SpriteStudio-SDK/libs/ssruntime/docs/` once the submodule is initialized).
