Develop
Develop
Select your platform

Spawn and remove 2D panels

Updated: Sep 17, 2025

Overview

To use 2D panels, you need to register and then spawn them in your scene. This page covers spawning panels at runtime or through Spatial Editor.

Spawn a panel to the scene

You can create a panel in two ways: using Spatial Editor or at runtime. Each method is suitable for different use case. Refer to the sections below for more details.
Both methods require assigning a registrationId to the panel. This is explained in Define an ID for the panel.

Spawn a panel using Spatial Editor

Spatial Editor provides visual control over panel size, position, and location. This approach works best for apps with a fixed number of panels.
Adding panels to Spatial Editor compositions is described in Panels in Spatial Editor. Use the registrationId from your registerPanels function as the panel ID (for example, @id/my_panel_id).
Spawn your panel by Spatial Editor
The next time you run your app, the panel with that registration ID will be spawned at the location defined in Spatial Editor.
For more information on Spatial Editor, see Spatial Editor overview.

Spawn a panel at runtime

This approach dynamically spawns your panels at runtime. This is useful when you don’t know the number of panels you need until the app is running. For example, a notes app may spawn a panel for each note.
To generate a panel and render it in a Spatial SDK scene, create an entity with a Panel component attached to it. This can be done using the helper function createPanelEntity in the Entity class.
val myPanelEntity = Entity.createPanelEntity(
    R.id.my_panel,
    Transform(Pose(Vector3(0f, 1.8f, 5f), Quaternion(0f, 0f, 0f))),
)

Removing a panel

To remove a panel, delete the associated entity.
myPanelEntity.destroy()

Safely destroying activity-based panels

Never use the finish() method to terminate an Activity associated with a panel. This causes crashes because memory references remain active for the panel’s resources: the 3D mesh, layer, texture, and Android surface.
Use panelEntity.destroy() to properly destroy Activity-based panels.
Did you find this page helpful?
Thumbs up icon
Thumbs down icon