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

MRUKRoom Class

Extends MonoBehaviour
Represents a room within MR Utility Kit, containing various MRUKAnchor objects and providing a set of utility functions.
Use this class to access on the anchors in a room, perform spatial queries or to share the room with other users.
This example demonstrates how to use the GenerateRandomPositionOnSurface method to find a random position on a specified surface type within the room.
float minRadius = 0.5f; // Minimum distance from the edge
// Generate a random position on the specified surface type
if (room.GenerateRandomPositionOnSurface(surfaceType, minRadius, new LabelFilter(MRUKAnchor.SceneLabels.FLOOR), out Vector3 pos, out Vector3 normal))
{
    if (room.IsPositionInRoom(spawnPosition) && !room.IsPositionInSceneVolume(spawnPosition))
    {
        // Position is valid and in the room
    }
}

Properties

Anchor : OVRAnchor
[Get]
The primary anchor associated with the room.
You should not need to use this directly, only use this if you know what you are doing.
Signature
OVRAnchor Anchor
AnchorCreatedEvent : UnityEvent< MRUKAnchor >
[Get]
Gets fired when a new anchor of this room has been created.
Signature
UnityEvent<MRUKAnchor> AnchorCreatedEvent
AnchorRemovedEvent : UnityEvent< MRUKAnchor >
[Get]
Gets fired when the anchor has been deleted.
Signature
UnityEvent<MRUKAnchor> AnchorRemovedEvent
Anchors : List< MRUKAnchor >
[Get]
Contains all the scene anchors in the room.
This example demonstrates how to iterate over all the anchors in the current room.
var room = MRUK.Instance.GetCurrentRoom();
foreach (var anchor in room.Anchors)
{
    Debug.Log($"Anchor is a {anchor.Label.ToString()}");
}
Signature
List<MRUKAnchor> Anchors
AnchorUpdatedEvent : UnityEvent< MRUKAnchor >
[Get]
Gets fired after a component of the corresponding anchor has changed (e.g.
the semantic label of a plane has changed from OTHER to STORAGE)
Signature
UnityEvent<MRUKAnchor> AnchorUpdatedEvent
CeilingAnchor : MRUKAnchor
[Get]
The ceiling anchor in the room.
Signature
MRUKAnchor CeilingAnchor
FloorAnchor : MRUKAnchor
[Get]
The floor anchor in the room.
Signature
MRUKAnchor FloorAnchor
GlobalMeshAnchor : MRUKAnchor
[Get]
The global mesh anchor in the room.
There is only one single instance of this object per room
Signature
MRUKAnchor GlobalMeshAnchor
IsLocal : bool
[Get]
A room is considered local if it was loaded from device.
If it was loaded from some other source, e.g. JSON or Prefab then it is not local.
Signature
bool IsLocal
SeatPoses : List< CouchSeat >
[Get]
Contains a list of suggested seat placements within the room, specifically on couch objects.
Each seat pose is defined relative to the couch anchor's space.
Signature
List<CouchSeat> SeatPoses
WallAnchors : List< MRUKAnchor >
[Get]
Contains all the wall anchors in the room.
Signature
List<MRUKAnchor> WallAnchors

Methods

DoesRoomHave ( labels )
Checks if the room contains all specified labels.
This method is obsolete. Use HasAllLabels instead. OVRSemanticLabels.DeprecationMessage
Signature
bool DoesRoomHave(string[] labels)
Parameters
labels: string[]  Array of label names to check.
Returns
bool  True if the room contains all specified labels, otherwise false.
FindLargestSurface ( anchorLabel )
Finds the largest surface within the room based on the specified anchor label.
This method is obsolete and should not be used in new code.
Signature
MRUKAnchor FindLargestSurface(string anchorLabel)
Parameters
anchorLabel: string  The label of the anchor as a string.
Returns
MRUKAnchor  The MRUKAnchor associated with the largest surface that matches the specified label.
FindLargestSurface ( labelFlags )
Finds the anchor with the largest available surface area that matches the specified label flags.
This method is more flexible than checking for specific conditions like table space and can be adapted for various usage scenarios.
Signature
MRUKAnchor FindLargestSurface(MRUKAnchor.SceneLabels labelFlags)
Parameters
labelFlags: MRUKAnchor.SceneLabels  The labels to consider when searching for the largest surface. These are represented as a combination of MRUKAnchor.SceneLabels.
Returns
MRUKAnchor  The MRUKAnchor with the largest surface area that matches the specified labels, or null if no suitable anchor is found.
GenerateRandomPositionInRoom ( minDistanceToSurface , avoidVolumes )
Generate a random position in a room, while avoiding volume scene objects and points that are too close to surfaces.
This function uses random sampling and a maximum number of iterations.
Signature
Vector3? GenerateRandomPositionInRoom(float minDistanceToSurface, bool avoidVolumes)
Parameters
minDistanceToSurface: float  Reject points whose proximity to a surface is less than the parameter.
avoidVolumes: bool  Do not allow points to be within volume scene objects.
Returns
Vector3?  A position that adhers to the constraints, null otherwise.
GenerateRandomPositionOnSurface ( surfaceTypes , minDistanceToEdge , labelFilter , position , normal )
Generate a position on any valid surface in the room, limited by the type of surface and the classification of the object.
Signature
bool GenerateRandomPositionOnSurface(MRUK.SurfaceType surfaceTypes, float minDistanceToEdge, LabelFilter labelFilter, out Vector3 position, out Vector3 normal)
Parameters
surfaceTypes: MRUK.SurfaceType  The type of surface by which to limit the generation.
minDistanceToEdge: float  Limit the generated point to not being close to a surface's edges and corners.
labelFilter: LabelFilter  The labels to include
position: out Vector3  The generated position. Vector3.zero is returned if no position was generated.
normal: out Vector3  The generated surface normal. Vector3.zero is returned if nothing was generated.
Returns
bool  True if a position was found, false otherwise.
GetBestPoseFromRaycast ( ray , maxDist , labelFilter , sceneAnchor , surfaceNormal , positioningMethod )
Calculates the best pose based on a raycast, considering specific label filters and positioning methods.
This method is useful for determining the optimal position and orientation for placing objects in a scene based on surface interactions. i.e. how best to "place an app/widget" on a surface.
  • When hitting vertical surfaces; Y is world-up, Z is surface normal.
  • When hitting horizontal surfaces; Y is world-up, Z is best-guess at player-facing.
  • "best guess" = when on ceiling/floor, Z faces player; when on surface (desk/couch), Z faces closest edge to player
Signature
Pose GetBestPoseFromRaycast(Ray ray, float maxDist, LabelFilter labelFilter, out MRUKAnchor sceneAnchor, out Vector3 surfaceNormal, MRUK.PositioningMethod positioningMethod=MRUK.PositioningMethod.DEFAULT)
Parameters
ray: Ray  The ray to cast into the scene.
maxDist: float  The maximum distance the ray should check for collisions.
labelFilter: LabelFilter  The filter to apply to scene anchors to determine which ones should be considered.
sceneAnchor: out MRUKAnchor  The scene anchor that the raycast hit, if any.
surfaceNormal: out Vector3  The normal of the surface at the hit point.
positioningMethod: MRUK.PositioningMethod  The method to use for positioning the pose. Defaults to MRUK.PositioningMethod.DEFAULT.
Returns
Pose  The best pose calculated from the raycast, or a default pose if no suitable surface is found.
GetBestPoseFromRaycast ( ray , maxDist , labelFilter , sceneAnchor , positioningMethod )
Calculates the best pose based on a raycast, considering specific label filters and positioning methods.
This version of the method does not return the surface normal explicitly.
Signature
Pose GetBestPoseFromRaycast(Ray ray, float maxDist, LabelFilter labelFilter, out MRUKAnchor sceneAnchor, MRUK.PositioningMethod positioningMethod=MRUK.PositioningMethod.DEFAULT)
Parameters
ray: Ray  The ray to cast into the scene.
maxDist: float  The maximum distance the ray should check for collisions.
labelFilter: LabelFilter  The filter to apply to scene anchors to determine which ones should be considered.
sceneAnchor: out MRUKAnchor  The scene anchor that the raycast hit, if any.
positioningMethod: MRUK.PositioningMethod  The method to use for positioning the pose. Defaults to MRUK.PositioningMethod.DEFAULT.
Returns
Pose  The best pose calculated from the raycast, or a default pose if no suitable surface is found.
GetCeilingAnchor ()
Retrieves the ceiling anchor of this room.
Signature
MRUKAnchor GetCeilingAnchor()
Returns
MRUKAnchor  The ceiling anchor.
GetFacingDirection ( anchor )
Get a "likely" direction this anchor is facing.
For planes, this is always the normal (Z-forward). For volumes, we use contextual clues; primarily, the closest wall is the "back" of the volume, and the facing direction is its axis most aligned with this wall normal.
Signature
Vector3 GetFacingDirection(MRUKAnchor anchor)
Parameters
anchor: MRUKAnchor  The anchor to evaluate.
Returns
Vector3  The facing direction of the anchor.
GetFloorAnchor ()
Retrieves the floor anchor of this room.
Signature
MRUKAnchor GetFloorAnchor()
Returns
MRUKAnchor  The floor anchor.
GetGlobalMeshAnchor ()
Retrieves the global mesh anchor of this room.
Signature
MRUKAnchor GetGlobalMeshAnchor()
Returns
MRUKAnchor  The global mesh anchor.
GetKeyWall ( wallScale , tolerance )
Identifies the key wall in the room.
A key wall is the longest wall with no other room points behind it, allowing for a more controlled artistic environment, akin to a stage. This method is useful for scenarios where a clear, unobstructed view of one wall is necessary. Can be used to craft a "stage-like" environment.
Signature
MRUKAnchor GetKeyWall(out Vector2 wallScale, float tolerance=0.1f)
Parameters
wallScale: out Vector2  Outputs the scale of the key wall, if found.
tolerance: float  A tolerance value to account for precision issues in determining if points are behind the wall.
Returns
MRUKAnchor  The anchor representing the key wall, or null if no suitable wall is found.
GetRoomAnchors ()
Returns all the Scene objects (anchors) in the room.
Useful if you want to do your own calculations within the Mixed Reality Utility Kit framework.
Signature
List< MRUKAnchor > GetRoomAnchors()
Returns
List< MRUKAnchor >  A list of MRUKAnchor objects representing the anchors in the room.
GetRoomBounds ()
Get a world-oriented bounding box of the room.
Signature
Bounds GetRoomBounds()
Returns
Bounds  The bounding box that encapsulates the entire room.
GetRoomOutline ()
Retrieves a clockwise (when viewed top-down) list of wall corner points at floor level.
This method is useful for obtaining the geometric outline of a room based on its walls.
Signature
List< Vector3 > GetRoomOutline()
Returns
List< Vector3 >  A list of Vector3 points representing the corners of the room's walls at floor level, arranged in a clockwise order.
GetSeatPoses ()
Returns all seats in the room (a human-spaced position on a couch).
Signature
Pose[] GetSeatPoses()
Returns
Pose[]  An array of poses representing all seats in the room.
GetWallAnchors ()
Retrieves the list of wall anchors of this room.
Signature
List< MRUKAnchor > GetWallAnchors()
Returns
List< MRUKAnchor >  A list of wall anchors.
HasAllLabels ( labelFlags )
Determines whether a room contains all the provided Scene API labels.
Signature
bool HasAllLabels(MRUKAnchor.SceneLabels labelFlags)
Parameters
labelFlags: MRUKAnchor.SceneLabels  The labels to check, represented as a combination of MRUKAnchor.SceneLabels.
Returns
bool  True if the room contains all specified labels, otherwise false.
IsPositionInRoom ( queryPosition , testVerticalBounds )
Tests if a given position is inside the floor outline of the room's walls.
This method can optionally test the vertical bounds to ensure the position is not outside the room's floor or ceiling, preventing the room from being treated as an "infinite column."
Signature
bool IsPositionInRoom(Vector3 queryPosition, bool testVerticalBounds=true)
Parameters
queryPosition: Vector3  The world position to test.
testVerticalBounds: bool  If true, the method also checks if the position is within the vertical bounds of the room (floor and ceiling). Defaults to true.
Returns
bool  True if the position is within the room's boundaries, false otherwise.
IsPositionInSceneVolume ( worldPosition , sceneObject , testVerticalBounds , distanceBuffer )
Test if a position is inside of a Scene volume, and optionally return the object.

To also check if a position is inside the room walls, use IsPositionInRoom().
Use distanceBuffer as a cheap way to check volume intersection.
Signature
bool IsPositionInSceneVolume(Vector3 worldPosition, out MRUKAnchor sceneObject, bool testVerticalBounds, float distanceBuffer=0.0f)
Parameters
worldPosition: Vector3  The world position to test.
sceneObject: out MRUKAnchor  The scene object that the position is inside of, if any.
testVerticalBounds: bool  Whether to test vertical bounds of the volume.
distanceBuffer: float  A buffer distance for volume intersection tests.
Returns
bool  True if the position is inside a scene volume, false otherwise.
IsPositionInSceneVolume ( worldPosition , distanceBuffer )
Test if a position is inside of a Scene volume (couch, desk, etc.).

To also check if a position is inside the room walls, use IsPositionInRoom().
Use distanceBuffer as a cheap way to check volume intersection.
Signature
bool IsPositionInSceneVolume(Vector3 worldPosition, float distanceBuffer=0.0f)
Parameters
worldPosition: Vector3  The world position to test.
distanceBuffer: float  A buffer distance for volume intersection tests, defaults to 0.0f.
Returns
bool  True if the position is inside a scene volume, false otherwise.
IsPositionInSceneVolume ( worldPosition , testVerticalBounds , distanceBuffer )
Test if a position is inside of a Scene volume (couch, desk, etc.).

To also check if a position is inside the room walls, use IsPositionInRoom().
Use distanceBuffer as a cheap way to check volume intersection.
///
Signature
bool IsPositionInSceneVolume(Vector3 worldPosition, bool testVerticalBounds, float distanceBuffer=0.0f)
Parameters
worldPosition: Vector3  The world position to test.
testVerticalBounds: bool  Whether to test vertical bounds of the volume.
distanceBuffer: float  A buffer distance for volume intersection tests, defaults to 0.0f.
Returns
bool  True if the position is inside a scene volume, false otherwise.
Raycast ( ray , maxDist , labelFilter , hit , outAnchor )
Casts a ray against ONLY Scene API objects, returning the closest result.
This method is used as a replacement for Physics.Raycast, specifically tailored to interact with Scene API objects.
Signature
bool Raycast(Ray ray, float maxDist, LabelFilter labelFilter, out RaycastHit hit, out MRUKAnchor outAnchor)
Parameters
ray: Ray  The ray to cast.
maxDist: float  The maximum distance the ray should check for collisions.
labelFilter: LabelFilter  The filter to apply to scene anchors to determine which ones should be considered.
hit: out RaycastHit  The closest RaycastHit result, if any.
outAnchor: out MRUKAnchor  The MRUKAnchor associated with the closest hit, if any.
Returns
bool  True if an object was hit, false otherwise.
Raycast ( ray , maxDist , hit , anchor )
Casts a ray against ONLY Scene API objects, returning the closest result.
This method is used as a replacement for Physics.Raycast, without specifying a label filter.
Signature
bool Raycast(Ray ray, float maxDist, out RaycastHit hit, out MRUKAnchor anchor)
Parameters
ray: Ray  The ray to cast.
maxDist: float  The maximum distance the ray should check for collisions.
hit: out RaycastHit  The closest RaycastHit result, if any.
anchor: out MRUKAnchor  The MRUKAnchor associated with the closest hit, if any.
Returns
bool  True if an object was hit, false otherwise.
Raycast ( ray , maxDist , labelFilter , hit )
Casts a ray against ONLY Scene API objects, returning the closest result.
This method is used as a replacement for Physics.Raycast, allowing for a specified label filter but not returning the anchor.
Signature
bool Raycast(Ray ray, float maxDist, LabelFilter labelFilter, out RaycastHit hit)
Parameters
ray: Ray  The ray to cast.
maxDist: float  The maximum distance the ray should check for collisions.
labelFilter: LabelFilter  The filter to apply to scene anchors to determine which ones should be considered.
hit: out RaycastHit  The closest RaycastHit result, if any.
Returns
bool  True if an object was hit, false otherwise.
Raycast ( ray , maxDist , hit )
Casts a ray against ONLY Scene API objects, returning the closest result.
This method is used as a replacement for Physics.Raycast, without specifying a label filter or returning the anchor.
Signature
bool Raycast(Ray ray, float maxDist, out RaycastHit hit)
Parameters
ray: Ray  The ray to cast.
maxDist: float  The maximum distance the ray should check for collisions.
hit: out RaycastHit  The closest RaycastHit result, if any.
Returns
bool  True if an object was hit, false otherwise.
RaycastAll ( ray , maxDist , labelFilter , raycastHits , anchorList )
Casts a ray against ONLY Scene API objects, returning all results.
This method is used as a replacement for Physics.RaycastAll, specifically tailored to interact with Scene API objects.
Signature
bool RaycastAll(Ray ray, float maxDist, LabelFilter labelFilter, List< RaycastHit > raycastHits, List< MRUKAnchor > anchorList)
Parameters
ray: Ray  The ray to cast.
maxDist: float  The maximum distance the ray should check for collisions.
labelFilter: LabelFilter  The filter to apply to scene anchors to determine which ones should be considered.
raycastHits: List< RaycastHit >  A list to store the RaycastHit results.
anchorList: List< MRUKAnchor >  A list to store the MRUKAnchor objects hit by the ray.
Returns
bool  True if one or more objects were hit, false otherwise.
RemoveAndDestroyAnchor ( anchor )
Removes an anchor from the internal list and destroys the gameobject and it's children.
Signature
void RemoveAndDestroyAnchor(MRUKAnchor anchor)
Parameters
anchor: MRUKAnchor  The Anchor to remove and destroy
Returns
void
ShareRoomAsync ( groupUuid )
Shares this room with the specified group.
Signature
async OVRTask< OVRResult< OVRAnchor.ShareResult > > ShareRoomAsync(Guid groupUuid)
Parameters
groupUuid: Guid  UUID of the group to which the room should be shared.
Returns
async OVRTask< OVRResult< OVRAnchor.ShareResult > >  A task that tracks the asynchronous operation.
Throws
InvalidOperationException  Thrown if Anchor is OVRAnchor.Null ArgumentException  Thrown if groupUuid is empty.
TryGetAnchorChildren ( queryAnchor , childAnchors )
Attempts to return the logical children of an anchor, if there are any.
This hierarchical relationship is by reference, not literally in the scene.
Signature
bool TryGetAnchorChildren(MRUKAnchor queryAnchor, out MRUKAnchor[] childAnchors)
Parameters
queryAnchor: MRUKAnchor  The anchor for which to find the children.
childAnchors: out MRUKAnchor[]  An array of child anchors, if any exist.
Returns
bool  True if there are one or more child anchors, otherwise false.
TryGetAnchorParent ( queryAnchor , parentAnchor )
Attempts to return the parent of an anchor, if it exists.
This hierarchical relationship is by reference, not literally in the scene.
Signature
bool TryGetAnchorParent(MRUKAnchor queryAnchor, out MRUKAnchor parentAnchor)
Parameters
queryAnchor: MRUKAnchor  The anchor for which to find the parent.
parentAnchor: out MRUKAnchor  The parent anchor, if one exists.
Returns
bool  True if the parent anchor exists, otherwise false.
TryGetClosestSeatPose ( ray , seatPose , couch )
Returns the best-suggested seat, for scenarios like remote caller placement.
Signature
bool TryGetClosestSeatPose(Ray ray, out Pose seatPose, out MRUKAnchor couch)
Parameters
ray: Ray  The ray to use for finding the closest seat.
seatPose: out Pose  The pose of the closest seat.
couch: out MRUKAnchor  The anchor associated with the closest seat.
Returns
bool  True if a seat is found, false otherwise.
TryGetClosestSurfacePosition ( worldPosition , surfacePosition , closestAnchor , labelFilter )
Attempts to find the closest surface position to a given world position within the room, considering only anchors that pass the specified label filter.
Signature
float TryGetClosestSurfacePosition(Vector3 worldPosition, out Vector3 surfacePosition, out MRUKAnchor closestAnchor, LabelFilter labelFilter=new())
Parameters
worldPosition: Vector3  The world position from which to find the closest surface.
surfacePosition: out Vector3  The closest surface position to the specified world position, if found.
closestAnchor: out MRUKAnchor  The anchor associated with the closest surface position, if found.
labelFilter: LabelFilter  A filter to apply to the anchors when searching for the closest surface. Defaults to an empty filter, which includes all labels.
Returns
float  The distance to the closest surface position. Returns Mathf.Infinity if no valid surface is found.
TryGetClosestSurfacePosition ( worldPosition , surfacePosition , closestAnchor , normal , labelFilter )
Attempts to find the closest surface position to a given world position within the room, considering only anchors that pass the specified label filter.
Signature
float TryGetClosestSurfacePosition(Vector3 worldPosition, out Vector3 surfacePosition, out MRUKAnchor closestAnchor, out Vector3 normal, LabelFilter labelFilter=new())
Parameters
worldPosition: Vector3  The world position from which to find the closest surface.
surfacePosition: out Vector3  The closest surface position to the specified world position, if found.
closestAnchor: out MRUKAnchor  The anchor associated with the closest surface position, if found.
normal: out Vector3  The normal of the closest surface position, if found.
labelFilter: LabelFilter  A filter to apply to the anchors when searching for the closest surface. Defaults to an empty filter, which includes all labels.
Returns
float  The distance to the closest surface position. Returns Mathf.Infinity if no valid surface is found.

Static Methods

SortWallsByWidth ( walls )
Sorts a list of wall anchors based on the width of their associated planes.
This method is useful for organizing walls in ascending order of their widths, which can be helpful for operations that require processing walls from narrowest to widest or for selecting specific walls based on their size.
Signature
static List< MRUKAnchor > SortWallsByWidth(List< MRUKAnchor > walls)
Parameters
walls: List< MRUKAnchor >  The list of wall anchors to sort.
Returns
List< MRUKAnchor >  A new list of wall anchors sorted by the width of their planes.

Inner Struct

CouchSeat Struct

Represents a seat poses in the room, that exist only on MRUKAnchor labeled as COUCH.
These are used as suggested placements for remote avatars. Use CalculateSeatPoses to populate a room's seat poses and access them through the SeatPoses list. couchPoses are in couchAnchor space.

Properties

couchAnchor : MRUKAnchor
[Get]
The MRUKAnchor associated with the couch.
This anchor provides the spatial context for the seat poses.
Signature
MRUKAnchor couchAnchor
couchPoses : List< Pose >
[Get]
A list of poses representing suggested placements for avatars or users on the couch.
Each pose is relative to the couch anchor's space.
Signature
List<Pose> couchPoses