Skip to content

QrScanner ​

Inherits: Node

Description ​

Scans QR codes with the headset cameras.

Uses the OpenXR spatial marker tracking extension (XR_EXT_spatial_marker_tracking). On Meta Quest this needs Horizon OS v83 or newer and the "Spatial Data" permission. Detection only runs while a scan is active: start() creates a QR code only spatial context and stop() frees it again, so the cameras aren't searching for codes the rest of the time.

Properties ​

NameTypeDefault
_component_dataArray[OpenXRSpatialComponentData][]
_contextRIDRID()
_discovery_cooldownfloat0.0
_discovery_pendingboolfalse
_discovery_started_atfloat0.0
_marker_trackingObjectnull
_scan_idint0
_scan_time_leftfloat0.0
_spatial_entitiesObjectnull
_stop_on_firstbooltrue
scanningboolfalse

Methods ​

ReturnsName
Variant_emit_marker ( text: String, pose: Transform3D, scan_id: int )
Variant_finish ( text: String, scan_id: int )
Variant_free_context ( context: RID )
Array[OpenXRMarkerTracker]_get_marker_trackers ( context: RID )
String_marker_data_to_text ( data: Variant )
Variant_on_context_created ( context: RID, scan_id: int )
Variant_on_snapshot ( _snapshot: RID, processed: bool, context: RID )
void_process ( delta: float )
void_ready ( )
bool_request_permission ( )
Variant_start_discovery ( )
boolis_supported ( )
QrScanner.ScanErrorstart ( timeout: float = 30.0, stop_on_first: bool = true )
Variantstop ( )

Signals ​

on_marker (text: String , pose: Transform3D ) ​

Emitted for every QR code seen during a scan started with stop_on_first = false, with its pose in tracking space, as often as the codes are detected. The scan keeps running.

on_scanned (text: String ) ​

Emitted with the content of the first QR code found during a scan. The scan stops right after.

on_scanning_changed (scanning: bool ) ​

Emitted when a scan starts or stops.

on_timeout ( ) ​

Emitted when a scan stops because no QR code was found in time.

Enums ​

enum ScanError ​

ScanError.OK = 0 ​

No description provided yet.

ScanError.UNSUPPORTED = 1 ​

The device or runtime can't detect QR codes.

ScanError.PERMISSION_DENIED = 2 ​

The user didn't grant the permission needed for QR code detection.

ScanError.CANCELLED = 3 ​

stop() was called before the scan started.

Constants ​

DEFAULT_TIMEOUT = 30.0 ​

Seconds a scan runs before giving up.

DISCOVERY_INTERVAL = 0.3 ​

Seconds between two discovery requests while scanning.

DISCOVERY_WATCHDOG = 3.0 ​

Seconds after which a discovery that never reported back is given up on.

QUEST_SCENE_PERMISSION = "com.oculus.permission.USE_SCENE" ​

Meta Quest only reports QR codes to apps with the Spatial Data permission.

Property Descriptions ​

_component_data: Array[OpenXRSpatialComponentData] ​

No description provided yet.

_context: RID ​

No description provided yet.

_discovery_cooldown: float ​

No description provided yet.

_discovery_pending: bool ​

No description provided yet.

_discovery_started_at: float ​

No description provided yet.

_marker_tracking: Object ​

No description provided yet.

_scan_id: int ​

Increased on every start and stop, so callbacks of an old scan can tell they're stale.

_scan_time_left: float ​

No description provided yet.

_spatial_entities: Object ​

No description provided yet.

_stop_on_first: bool ​

No description provided yet.

scanning: bool ​

No description provided yet.

Method Descriptions ​

_emit_marker (text: String , pose: Transform3D , scan_id: int ) -> Variant ​

No description provided yet.

_finish (text: String , scan_id: int ) -> Variant ​

No description provided yet.

_free_context (context: RID ) -> Variant ​

No description provided yet.

_get_marker_trackers (context: RID ) -> Array[OpenXRMarkerTracker] ​

No description provided yet.

_marker_data_to_text (data: Variant ) -> String ​

No description provided yet.

_on_context_created (context: RID , scan_id: int ) -> Variant ​

No description provided yet.

_on_snapshot (_snapshot: RID , processed: bool , context: RID ) -> Variant ​

Called by the marker tracking capability once before (processed = false) and once after the snapshot has been turned into OpenXRMarkerTrackers.

_process (delta: float ) -> void ​

No description provided yet.

_ready ( ) -> void ​

No description provided yet.

_request_permission ( ) -> bool ​

No description provided yet.

_start_discovery ( ) -> Variant ​

No description provided yet.

is_supported ( ) -> bool ​

Returns true if QR codes can be scanned on this device. Only reliable once the XR session is running.

start (timeout: float = 30.0 , stop_on_first: bool = true ) -> QrScanner.ScanError ​

Starts scanning for QR codes. The first QR code found is emitted with on_scanned. With stop_on_first false, every detection is emitted with on_marker instead, until stop() is called or the scan times out. Returns once the scan is running or failed to start.

stop ( ) -> Variant ​

Stops the current scan, if any.