Develop
Develop
Select your platform

Hot reload features in Meta Spatial Editor

Updated: Jun 24, 2025

Overview

The Send to device feature simplifies development by allowing instant headset previews of Meta Spatial Editor compositions, known as hot reload. Without this feature, you must manually rebuild and reinstall via Android Studio after each change, which slows the workflow. This guide explains two methods for using hot reload: employing the Gradle Plugin and sending updates directly from Meta Spatial Editor.

Prerequisites

To test your Meta Spatial Editor projects on a headset, they must first be integrated with the Meta Spatial SDK. Additionally, you must configure your application to have the HotReloadFeature enabled to avoid a HotReload not enabled error.

Set up hot reload

  1. In the [versions] block of your libs.versions.toml file, add a variable called spatialsdk if there isn’t one already.
     spatialsdk = "0.8.1"
    
  2. In the [libraries] block, add the hot reload library.
     meta-spatial-sdk-hotreload = { group = "com.meta.spatial", name = "meta-spatial-sdk-hotreload", version.ref = "spatialsdk" }
    
  3. In the dependencies {} block of app/build.gradle.kts, add the new dependency.
      dependencies {
         implementation(libs.meta.spatial.sdk.hotreload) }
    
  4. In the spatial {} block, add the appropriate config options. Note: this step is only needed for the Gradle Plugin based hot reload.
     spatial {
         hotReload {
             appPackage.set("com.your.package")
             appMainActivity.set("com.your.package.YourActivity")
             assetsDir.set(File("src/main/assets"))
         }
     }
    
  5. In your app’s main activity file, register HotReloadFeature.
     class MyActivity : AppSystemActivity() {
     override fun registerFeatures(): List<SpatialFeature> {
      return listOf(
          ... // other features here
          HotReloadFeature(this))
    } }
    
    
Spatial Editor allows direct updates to compositions on devices with a button press using the Send to device feature, bypassing the Gradle Plugin. This provides a streamlined workflow for instant previews and live scene editing of .glxf, .gltf, or .glb files. It eliminates the need for app rebuilds after changes.
Before you begin, make sure you’ve completed these steps:
  1. Connect your device.
  2. Install the target APK (the associated Android project) on your device.
Note for designers: If you’re new to Android Studio, ask someone to build and install the APK for you. This only needs to be done once.
Send updates from Meta Spatial Editor:
  1. Edit your project.
  2. In the Meta Spatial Editor toolbar, click Send to device.
  3. If you see a prompt, ensure the device is selected and the app is running. (Click Launch app).
  4. Click Send.
  5. Changes will be sent when the info button stops turning. View updates in the headset.

How Spatial Editor’s Send to Device button works

Spatial Editor uses an integrated ADB executable to streamline device and app setup, and to identify the hot reload feature. It exports the complete project and transmits the files to the Spatial SDK APK on the headset via ADB, initiating the hot reload process.
The changes you previewed in the headset don’t apply directly to the APK on the device. Instead, they apply through intermediate caches. Therefore, relaunching the APK on the headset won’t display the changes. To see the updates, you must either click Send to device again or rebuild the APK with the updated Spatial Editor project.
Note: Spatial Editor’s hot reload/Send to device button only works with Spatial SDK >= v0.7.0.

Method 2: Use the Gradle Plugin (For specific use cases)

The Gradle Plugin provides a more comprehensive build and deployment automation for larger or more complex projects.
The Meta Spatial Gradle plugin has a built-in Gradle task called hotReload. It allows you to install and run your Meta Spatial application while listening to your local file changes.
Steps to use the Gradle plugin:
  1. Ensure the hotReload Gradle task is synced by clicking Sync Project with Gradle Files in Android Studio:
    Sync Gradle files
  2. Enable Configure all Gradle tasks during Gradle Sync in Android Studio settings:
    Gradle task
  3. Locate the hotReload Gradle task. If it’s missing, rebuild your task list during Gradle sync:
    Gradle task
  4. Run the hotReload Gradle task by right-clicking on it and selecting Run Sample:app:[hotReload]:
    Run Gradle task
Android Studio will install and run the Meta Spatial application. Once the application fully loads in your headset, the Gradle task starts a background process to monitor file changes and hot reload them. If you have the export task set up, all you need to do is save your changes in Spatial Editor. Then it will auto-export the project to your assets folder and initiate the hot reload.
Gradle task tab
With hot reload enabled, you don’t have to re-run the application every time you make a change to a .glxf, .gltf or .glb file. You can also live edit your scene using Meta Spatial Editor, and your scene will be in real-time when you save your changes.

Shader hot reload

When you have both hot reload and custom shaders configured, you can edit custom shaders in real-time without restarting your app. This feature saves significant time, especially for visual adjustments and testing changes not accessible during app startup.

Prerequisites for shader hot reload

  • At least v0.8.1 of Meta Spatial SDK.
  • Custom shader setup:
    • NDK installed and specified in your app
    • shaders extension added to your spatial plugin, pointing to your shader sources
    • App compiles with shaders compiling correctly
  • Shader compilation enabled:
    • Set enableShaderCompilation to true in your hotReload extension (this is the default)
    • Disable this only if you don’t want shader recompilation with hot reloading
See the Custom Shaders guide for detailed shader setup instructions.

Using shader hot reload

Shader hot reload works automatically when you have both hot reload and custom shaders configured:
  1. Run the hot reload Gradle task (Method 2 above)
    • This launches your app on your device and listens for changes
  2. Optional: Use casting to avoid wearing your headset
  3. Navigate to any .vert or .frag file in your shader sources and make changes
  4. Save your file
  5. Watch your shaders reload instantly on your device!
The shader hot reload combines the existing hot reload and custom shader tools, enabling real-time shader editing without manual rebuilds.

Restrictions

The default hot reload mode, DELETE_AND_RECREATE_ENTITIES, deletes and recreates all entities from your Spatial Editor project using the reloaded version. This can cause app crashes if your code references deleted entities. While an alternative KEEP_EXISTING_ENTITIES mode exists, we recommend using the default mode as the alternative is still being improved.

Best practice for saving entity references

For versions 0.7.0 and later, use the OnLoaded callback from glXFManager.inflateGLXF instead of invokeOnCompletion to assign entity references. The OnLoaded callback ensures correct setup of new entity references after a hot reload. Below, you’ll find example code illustrating this best practice:
private var myEntity: Entity? = null

// Not recommended pattern:

loadGLXF().invokeOnCompletion {
    val composition = glXFManager.getGLXFInfo("example_key_name")
    myEntity = composition.getNodeByName("my_node_name").entity
}

private fun loadGLXF(): Job {
    gltfxEntity = Entity.create()
    return activityScope.launch {
        glXFManager.inflateGLXF(
            Uri.parse("apk:///scenes/Composition.glxf"),
            rootEntity = gltfxEntity!!,
            keyName = "example_key_name"
        )
    }
}

// Recommended pattern:

loadGLXF { composition ->
    myEntity = composition.getNodeByName("my_node_name").entity
}

private fun loadGLXF(onLoaded: ((GLXFInfo) -> Unit) = {}): Job {
    gltfxEntity = Entity.create()
    return activityScope.launch {
        glXFManager.inflateGLXF(
            Uri.parse("apk:///scenes/Composition.glxf"),
            rootEntity = gltfxEntity!!,
            onLoaded = onLoaded
        )
    }
}

Troubleshooting

When building your app, you might encounter an error stating that the glXF file cannot be found or parsed. This usually means the export task did not run automatically. To resolve this issue, you need to manually execute the export Gradle task. Here’s how:
  1. Locate the export Gradle task in the same list where you found the hotReload task.
  2. Run the export task manually.
Once you’ve run the export task, the hot reload function should work as expected.
Did you find this page helpful?
Thumbs up icon
Thumbs down icon