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

MRUKFeature Class

Implements SpatialFeature
Modifiers: final
MRUK - Mixed Reality Utility Kit
MRUK offers enhanced scene-related functionality utilizing OpenXR scene APIs. It facilitates loading rooms along with their scene anchors. Additionally, MRUK supports loading scenes from JSON files (as demonstrated in the MRUK sample), enabling testing of various room configurations. Take a look at MrukSampleActivity to see how it can be used. The MRUKFeature serves as the primary entry point for MRUK, handling the loading of scene data from the device. If loadSceneFromDevice or loadSceneFromJsonString are called multiple times MRUK will add, update, and remove rooms to keep the rooms in MRUKFeature in sync with the rooms that are in the system. MRUKFeature provides callbacks that can be used to get notified when rooms or anchors get added, updated, or removed.

Constructors

MRUKFeature ( context , systemManager )
Signature
constructor(context: Context, systemManager: SystemManager)
Parameters
context: Context
systemManager: SystemManager

Properties

context : Context
[Get]
Signature
val context: Context
rooms : MutableList
[Get]
List of all currently loaded rooms in the scene.
Rooms are added, updated, or removed when loading scene data via MRUKFeature.loadSceneFromDevice or MRUKFeature.loadSceneFromJsonString. Use MRUKSceneEventListener to receive notifications when rooms change.
Signature
val rooms: MutableList<MRUKRoom>
systemManager : SystemManager
[Get]
Signature
val systemManager: SystemManager

Functions

addSceneEventListener ( listener )
Registers a listener for scene events.
This function adds a listener that will be notified when rooms or anchors are added, updated, or removed. Use this to respond to changes in the scene, such as when a new room is discovered or when an anchor's position is updated.
Signature
fun addSceneEventListener(listener: MRUKSceneEventListener)
Parameters
  The MRUKSceneEventListener implementation to register
clearRooms ()
Clears all loaded rooms and their associated resources.
This function removes all rooms from memory and cleans up their resources. This is useful when you want to reset the state of the MRUK system or prepare for loading a new set of rooms.
Signature
fun clearRooms()
componentsToRegister ()
Override this function to define a list of components that should be used by the application.
Signature
open override fun componentsToRegister(): List<ComponentRegistration>
Returns
List
  A list of ComponentRegistration objects representing the components to register.
configureTrackers ( trackers )
Configures and starts the specified object trackers.
This function enables tracking of real-world objects like keyboards and QR codes. Once configured, the system will begin detecting and tracking these objects in the environment. When objects are detected, they will trigger the appropriate callbacks.
Signature
fun configureTrackers(trackers: Set<Tracker>): CompletableFuture<MRUKStartTrackerResult>
Parameters
trackers: Set
  A set of Tracker enum values specifying which trackers to enable (e.g., Tracker.Keyboard, Tracker.QrCode)
Returns
CompletableFuture
  A CompletableFuture that completes with MRUKStartTrackerResult.SUCCESS when the trackers are successfully configured, or with an error result if configuration fails
earlySystemsToRegister ()
Override this method to register your systems that should be executed with PriorityGroup EARLY.
Signature
open fun earlySystemsToRegister(): List<SystemBase>
Returns
List
  A list of SystemBase objects
findRoom ( roomUuid )
Finds a room that matches the given UUID.
A room in MRUK represents a mapped physical space containing anchors for walls, floors, ceilings, and other detected elements. This function searches through all loaded rooms to find one with a matching UUID.
Signature
fun findRoom(roomUuid: UUID): MRUKRoom?
Parameters
roomUuid: UUID
  The UUID of the room to find
Returns
  The matching MRUKRoom object if found, or null if no room with the specified UUID exists
getCurrentRoom ()
Gets the room that the user is currently in, based on head position.
This function attempts to determine which room the user is currently in by checking if the user's head position is within any of the loaded rooms. If the user is not in any room, it defaults to the first room in the list (if any rooms are loaded).
Signature
fun getCurrentRoom(): MRUKRoom?
Returns
  The current room, or null if no rooms are loaded or the user is not in any room and there are no rooms to default to
getDependencies ()
Override this method to define a list of dependencies required by this feature. This will be verified at runtime.
Example:
// MyCustomFeature.kt
override fun getDependencies(): List<KClass<out SpatialFeature>> {
  return listOf(ToolkitFeature::class)
}
@return A list of SpatialFeature classes representing the dependencies.

Signature
open fun getDependencies(): List<KClass<out SpatialFeature>>
Returns
List
getEnvironmentRaycasterStatus ()
Get the environment raycasters current status.
Signature
fun getEnvironmentRaycasterStatus(): MRUKEnvironmentRaycasterStatus
Returns
  The raycaster status.
isWorldLockingEnabled ()
Returns whether World Locking is currently enabled.
Signature
fun isWorldLockingEnabled(): Boolean
Returns
Boolean
  true if World Locking is enabled, false otherwise.
lateSystemsToRegister ()
Override this method to register your systems that should be executed with PriorityGroup LATE.
Signature
open fun lateSystemsToRegister(): List<SystemBase>
Returns
List
  A list of SystemBase objects
loadLibrary ( libName )
Loads a native library into the application.
Signature
open fun loadLibrary(libName: String)
Parameters
libName: String
  The name of the library to load.
loadSceneFromDevice ( requestSceneCaptureIfNoDataFound , removeMissingRooms , sceneModel )
Load the scene from the device.
Signature
fun loadSceneFromDevice(requestSceneCaptureIfNoDataFound: Boolean = true, removeMissingRooms: Boolean = true, sceneModel: SceneModel = SceneModel.V1): CompletableFuture<MRUKLoadDeviceResult>
Parameters
requestSceneCaptureIfNoDataFound: Boolean
  if set to true and no scene data is found the user will be prompted by space setup to setup their room.
removeMissingRooms: Boolean
  if set to true any rooms that aren't found on the device anymore will be removed. Usually this the behavior you want. If you want to have rooms loaded from the device and rooms from JSON co-exist you want to set removeMissingRooms to false.
sceneModel: SceneModel
Returns
CompletableFuture
loadSceneFromJsonString ( jsonString , removeMissingRooms , sceneModel )
Load the scene from a JSON string.
Signature
fun loadSceneFromJsonString(jsonString: String, removeMissingRooms: Boolean = true, sceneModel: SceneModel = SceneModel.V1)
Parameters
jsonString: String
  A JSON string that may contain multiple rooms
removeMissingRooms: Boolean
  if set the MRUK library will remove any rooms that are not in the file. Usually this the behavior you want. If you want to have rooms loaded from the device and rooms from JSON co-exist you want to set removeMissingRooms to false.
sceneModel: SceneModel
onCreate ( savedInstanceState )
Called when the application is created. Override this method to perform actions during the OnCreate() lifecycle of the application.
Signature
open override fun onCreate(savedInstanceState: Bundle?)
Parameters
savedInstanceState: Bundle?
  The saved instance state of the application.
onDestroy ()
Called when the application is in onDestroy callback. Be aware that onDestroy() is not guaranteed to be called. Override this method to perform actions during the OnDestroy() lifecycle of the application.
Signature
open fun onDestroy()
onPauseActivity ()
Called when the activity is in onPause callback. Override this method to perform actions during the OnPause() lifecycle of the application.
Signature
open fun onPauseActivity()
onResume ()
Called when the application is resumed. Override this method to perform actions during the OnResume() lifecycle of the application.
Signature
open fun onResume()
onSceneReady ()
Called when the scene is ready. Override this method to perform actions during the OnSceneReady() lifecycle of the application.
Signature
open fun onSceneReady()
onSpatialShutdown ()
Called when the application is shutting down. Clean up all Spatial resources for your feature, e.g. entites.destroy(), in this callback.
Signature
open override fun onSpatialShutdown()
onStart ()
Called when the application is started. Override this method to perform actions during the OnStart() lifecycle of the application.
Signature
open fun onStart()
onStopActivity ()
Called when the activity is in onStop callback. Be aware that onStop() is not guaranteed to be called. Override this method to perform actions during the OnStop() lifecycle of the application.
Signature
open fun onStopActivity()
onVRPause ()
Called when the VR mode is paused. Override this method to perform actions during the OnVRPause() lifecycle of the application.
Signature
open fun onVRPause()
onVRReady ()
Called when the VR mode is ready. Override this method to perform actions during the onVRReady() lifecycle of the application.
Signature
open fun onVRReady()
preRuntimeOnCreate ( savedInstanceState )
Called before the application's onCreate() method is called. Override this method to perform actions before the rest of the OnCreate() lifecycle of the application.
Signature
open fun preRuntimeOnCreate(savedInstanceState: Bundle?)
Parameters
savedInstanceState: Bundle?
  The saved instance state of the application.
raycastEnvironment ( origin , direction , maxDistance )
Performs a raycast in the environment and returns the first hit.
This function casts a ray from the specified origin in the given direction and returns information about the first hit. The raycast is performed against the depth of the real world. Which means no space setup is required prior to using this function. Note that this raycast does not interact with any spatial scene anchors. For that use raycastRoom.
Note: Before calling this function, startEnvironmentRaycaster() must be invoked to initialize the environment raycaster.
Signature
fun raycastEnvironment(origin: Vector3, direction: Vector3, maxDistance: Float = Float.MAX_VALUE): MRUKEnvironmentRaycastHit
Parameters
origin: Vector3
  The starting point of the ray in world space
direction: Vector3
  The direction of the ray (should be normalized)
maxDistance: Float
  The maximum distance the ray should travel (defaults to Float.MAX_VALUE)
Returns
  An MRUKEnvironmentRaycastHit object containing the result status and hit details. Check the result field for SUCCESS, NOT_READY, or NO_HIT to determine the outcome
raycastRoom ( roomUuid , origin , direction , maxDistance , surfaceType )
Performs a raycast against surfaces in the specified room and returns the first hit.
Signature
fun raycastRoom(roomUuid: UUID, origin: Vector3, direction: Vector3, maxDistance: Float = Float.POSITIVE_INFINITY, surfaceType: SurfaceType = SurfaceType.ALL): MRUKHit?
Parameters
roomUuid: UUID
  The UUID of the room to raycast against
origin: Vector3
  The starting point of the ray in world space
direction: Vector3
  The direction of the ray (should be normalized)
maxDistance: Float
  The maximum distance the ray should travel (defaults to infinity)
surfaceType: SurfaceType
  The type of surfaces to include in the raycast (planes, volumes, meshes)
Returns
  The first hit result, or null if no surface was hit
raycastRoomAll ( roomUuid , origin , direction , maxDistance , surfaceType )
Performs a raycast against surfaces in the specified room and returns all hits. The hits are sorted by distance from closest to farthest.
Signature
fun raycastRoomAll(roomUuid: UUID, origin: Vector3, direction: Vector3, maxDistance: Float = Float.POSITIVE_INFINITY, surfaceType: SurfaceType = SurfaceType.ALL): Array<MRUKHit>
Parameters
roomUuid: UUID
  The UUID of the room to raycast against
origin: Vector3
  The starting point of the ray in world space
direction: Vector3
  The direction of the ray (should be normalized)
maxDistance: Float
  The maximum distance the ray should travel (defaults to infinity)
surfaceType: SurfaceType
  The type of surfaces to include in the raycast (planes, volumes, meshes)
Returns
Array
  An array of all hit results, empty if no surfaces were hit
registerRequiredOpenXRExtensions ()
Override this function to define a list of required OpenXR extensions that should be enabled by your application.
Signature
open override fun registerRequiredOpenXRExtensions(): List<String>
Returns
List
  A list of strings representing the required OpenXR extensions.
removeSceneEventListener ( listener )
Unregisters a previously added scene event listener.
This function removes a listener that was previously registered with addSceneEventListener(), stopping it from receiving notifications about scene changes. Call this when you no longer need to receive scene event notifications or when cleaning up resources.
Signature
fun removeSceneEventListener(listener: MRUKSceneEventListener)
Parameters
  The MRUKSceneEventListener implementation to unregister
requestSceneCapture ()
Brings up the system dialog that prompts the user to set up a space (room mapping).
This function initiates the space setup process, which guides the user through mapping their physical environment. During this process, the system will identify walls, floors, ceilings, and other key elements of the space. Once completed, this spatial data becomes available to the application.
This function can be called:
  • Explicitly when you want to force a new space setup
  • Automatically by loadSceneFromDevice() when no room data exists
Signature
fun requestSceneCapture(): CompletableFuture<Unit>
Returns
CompletableFuture
  A CompletableFuture that completes when the user finishes the space setup process or cancels it. The future completes with Unit (void) and does not provide information about whether the setup was successful. To check for success, verify if rooms were added after the future completes.
saveSceneToJsonString ()
Saves the current scene data to a JSON string.
This function serializes all loaded rooms and their anchors into a JSON format that can be stored and later reloaded using loadSceneFromJsonString(). This is useful for:
  • Saving room configurations for later use
  • Sharing room data between different app sessions
  • Testing with predefined room layouts
Signature
fun saveSceneToJsonString(): String
Returns
String
  A JSON string containing the serialized scene data
setWorldLockingEnabled ( enabled )
World Locking keeps virtual content stationary relative to the real world without manually parenting every object to anchors. When enabled (default true), MRUK applies subtle camera adjustments so anchors remain aligned. This allows your virtual objects to stay "static" in world space, improving stability and reducing the need to parent to each anchor.
Signature
fun setWorldLockingEnabled(enabled: Boolean)
Parameters
enabled: Boolean
  Set to true to enable World Locking, false to disable it
startEnvironmentRaycaster ()
Starts the environment raycaster.
This function initializes the environment raycaster, which is used to perform raycasting operations in the environment. It requires the scene permission to function. This function must be called before using raycastEnvironment. Note that the raycaster takes a few frames to be ready, but its allowed to call raycastEnvironment even if they raycaster is not ready yet. In addition, getEnvironmentRaycasterStatus allows to check if the raycaster is ready.
Signature
fun startEnvironmentRaycaster(): MRUKStartEnvironmentRaycasterResult
Returns
  MRUKStartEnvironmentRaycasterResult.SUCCESS on success, or an error result if the operation fails.
stopEnvironmentRaycaster ()
Stops the environment raycaster.
This function deactivates the environment raycaster, preventing any further raycasting operations in the environment. After calling this function, raycastEnvironment can no longer be used until the raycaster is started again with startEnvironmentRaycaster.
Signature
fun stopEnvironmentRaycaster()
stopTrackers ()
Stops all active object trackers.
This function disables any previously configured trackers (keyboards, QR codes, etc.) and stops the system from detecting and tracking these objects. Call this function when you no longer need tracking functionality or when switching between different tracking modes.
Signature
fun stopTrackers()
systemsToRegister ()
Override this method to register your systems that should be executed PriorityGroup NORMAL.
Signature
open override fun systemsToRegister(): List<SystemBase>
Returns
List
  A list of SystemBase objects
Did you find this page helpful?