Spawn and remove 2D panels
Updated: Sep 17, 2025
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.
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).
The next time you run your app, the panel with that registration ID will be spawned at the location defined in Spatial Editor.
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))),
)
To remove a panel, delete the associated entity.
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.