By the end of this tutorial, you’ll have created a new Spatial SDK app and previewed it on your headset. Creating a new Spatial SDK app is the quickest way to get started with the SDK. You aren’t constrained by the structure of an existing codebase.
This tutorial builds on the CustomComponentsStarter sample, which contains the boilerplate of CustomComponentsSample and gives you a structure to build a custom component on. Two other starting points also create a Spatial SDK app:
Project template: the Meta VR Plugin for Android Studio generates a new Spatial SDK project from the Android Studio New Project wizard.
Starter Sample: StarterSample in the Meta Spatial SDK Samples repository is a runnable template project that shows the activity, scene, and panel structure of a Spatial SDK app. To use it, download or clone the repository, open the StarterSample project in Android Studio, connect your headset, and then click Run ‘app’. See Starter Sample.
Sample prerequisites
Install Meta Spatial Editor before you build CustomComponentsStarter. Samples in the Meta Spatial SDK Samples repository that export a Spatial Editor project require Meta Spatial Editor for that export. MrukSample, PremiumMediaSample, and BodyTrackingSample do not ship a project under app/scenes. Spatial SDK itself does not require Meta Spatial Editor, because you can create entities and place objects in code.
If a Gradle export fails with Meta Spatial Editor CLI not found, the export task cannot locate the Spatial Editor CLI. Install Meta Spatial Editor, which installs the CLI alongside it. If the CLI is installed somewhere else, set cliPath in the spatial { scenes { ... } } block, as described in Using a Spatial Editor project with Spatial SDK.
Preview the app on Meta VR
For brand new projects, project templates are the fastest way to get started, but this tutorial uses the CustomComponentsStarter sample as the foundation of your new app to provide some structure and custom scripts. To download and preview the CustomComponentsStarter sample, follow these steps.
Once the folder is downloaded, right-click on the folder and extract all files.
In Android Studio, in the CodelabStarters folder, open the CustomComponentsStarter project.
Gradle will begin building, indicated by the progress bar in the lower-right corner of Android Studio.
If a Trust and Open Project window appears, select Trust Project.
In your headset, ensure you are on your home screen.
Once Gradle has finished building, in the Android Studio toolbar, click the green Run ‘app’ button.
Once the starter app has finished building, it will launch automatically on your headset. It should look like this.
(Optional) Explore the Spatial SDK app directories
In Android Studio, familiarize yourself with the structure of the Spatial SDK app to effectively navigate and utilize its features.
App directory:
app/src/main/java: Contains source files for the Spatial SDK or immersive application.
app/scenes: Contains the Main.metaspatial file, 3D models, and textures.
app/scenes/Composition: Includes the Main.metaspatialcomp file, the main composition file.
Gradle directory: Configuration has been pre-set for you.
Note: If your project directory doesn’t match the file paths listed above, make sure the drop-down at the top of the directory is set to Project.
(Optional) Open the composition in Spatial Editor
Spatial SDK stores information about a scene’s 2D and 3D objects and their associated audio, materials, and components in a composition file. To edit a composition file, you open it in the Meta Spatial Editor.
In the Android Studio file hierarchy, open the Main.metaspatial file.
Right-click the file.
Select either Open In > Finder (for Mac), or Open In > Explorer (for Windows).
Double-click the file to open it in Spatial Editor.