API reference
API reference
Select your platform
No SDKs available
No versions available

VrActivity

VrActivity

open class VrActivity
VrActivity serves as the base class inherited by AppSystemActivity, which should be used for creating Spatial Activities instead of directly subclassing VrActivity. This class provides essential functionalities required by all Meta Spatial applications, including:
  • Lifecycle management: Handles Android lifecycle events.
  • Input management: Manages user inputs within the virtual environment.
  • Scene management: Oversees the creation and updating of scenes, helping to organize content and manage rendering.
  • DataModel setup: Prepares and manages the data models necessary for application functionality.
As a subclass of Android’s Activity, VrActivity includes all standard Android lifecycle callbacks, such as onCreate().

Constructors

NameSummary
VrActivity
constructor()

Types

NameSummary
Companion
object Companion

Properties

NameSummary
componentManager
val componentManager: ComponentManager
scene
var scene: Scene
spatialContext
var spatialContext: SpatialContext
systemManager
val systemManager: SystemManager

Functions

NameSummary
dispatchGenericMotionEvent
open fun dispatchGenericMotionEvent(event: <Error class: unknown class>): Boolean
Dispatches a generic motion event to the appropriate game controller.
dispatchKeyEvent
open fun dispatchKeyEvent(event: <Error class: unknown class>): Boolean
Dispatches a key event to the appropriate game controller.
doFrame
open fun doFrame(frameTimeNanos: Long)
Called when a new display frame is being rendered.
findFeature
inline fun <T : SpatialFeature> findFeature(): T
fun <T : SpatialFeature> findFeature(clazz: KClass<T>): T
getComponentManager
fun getComponentManager(): ComponentManager
Returns the singleton component manager for the application.
getDataModel
fun getDataModel(): DataModel
Returns the singleton DataModel for the application.
getGameControllerDeviceIds
fun getGameControllerDeviceIds(): Set<Int>
Returns a set of device IDs for all connected game controllers.
getSceneObject
fun getSceneObject(): Scene
Returns the singleton scene object for the application.
getSystemManager
fun getSystemManager(): SystemManager
Returns the singleton system manager for the application.
loadLibrary
open fun loadLibrary(name: String)
Loads a native C++ library. This method should be called in onCreate().
onCreate
open fun onCreate(savedInstanceState: <Error class: unknown class>?)
Called when the VRActivity is first created. This method creates the necessary building blocks for a Spatial application. It initializes the VrActivity, including loading the Meta Spatial SDK library, registering game controller management, creating a new spatial instance, and initializing the SpatialFeature manager.
onDestroy
open fun onDestroy()
Called when the app is destroyed. VrActivity::onDestroy will clean up all the resources and trigger garbage collection. If you override this method, be sure to call super.onDestroy().
onHMDMounted
open fun onHMDMounted()
onHMDUnmounted
open fun onHMDUnmounted()
onPause
open fun onPause()
Called as part of the activity lifecycle when an activity is going into the background, but has not yet been killed. The counterpart to onResume(). If you override this method, be sure to call super.onPause().
onPostResume
open fun onPostResume()
Called after activity resume is complete. If you override this method, be sure to call super.onPostResume().
onRecenter
open fun onRecenter()
This hook is called when the VRActivity is recentered.
onResume
open fun onResume()
Called when the activity will start interacting with the user. If you override this method, be sure to call super.onResume()
onSceneReady
open fun onSceneReady()
This hook is called on the first onResume(), after the scene is loaded in onCreate(). It will invoke all the onSceneReady() hooks of the registered SpatialFeatures.
onSceneTick
open fun onSceneTick()
Called every tick in the application to update the scene.
onStart
open fun onStart()
Called when the activity is becoming visible to the user. If you override this method, be sure to call super.onStart().
onStop
open fun onStop()
Called when the app is no longer visible to the user. You will next receive either onRestart(), onDestroy(), or nothing, depending on later user activity. If you override this method, be sure to call super.onStop().
onVRPause
open fun onVRPause()
This hook is called when the VRActivity switches from immersive to non-immersive mode. It will invoke all the onVRPause() hooks of the registered SpatialFeatures.
onVRReady
open fun onVRReady()
This hook is called when the immersive Spatial application is first loaded or is changed from 2D mode to immersive (VR) mode. It will invoke all the onVRReady() hooks of the registered SpatialFeatures.
pinGameController
fun pinGameController(deviceId: Int, func: (<Error class: unknown class>?, <Error class: unknown class>?) -> Unit)
Pins a game controller with the given device ID and associates it with the given function.
registerFeatures
open fun registerFeatures(): List<SpatialFeature>
Override this method to register your own SpatialFeatures. This is called in onCreate().
registerRequiredOpenXRExtensions
open fun registerRequiredOpenXRExtensions(): List<String>
registerSystemFeatures
open fun registerSystemFeatures(): List<SpatialFeature>
runOnMainThread
fun runOnMainThread(runnable: Runnable)
This method provides a way to run a Runnable on the activity’s main thread.
setBaseHref
open fun setBaseHref(baseHref: String)
Sets the base href for the application.
tryFindFeature
inline fun <T : SpatialFeature> tryFindFeature(): T?
fun <T : SpatialFeature> tryFindFeature(clazz: KClass<T>): T?
unpinGameController
fun unpinGameController(deviceId: Int)
Unpins a game controller with the given device ID.
useVolumes
open fun useVolumes(): Boolean

Companion

object Companion
Did you find this page helpful?
Thumbs up icon
Thumbs down icon