OpenXRMetaColocationDiscoveryExtensionWrapper
Inherits: OpenXRExtensionWrapperExtension
Wraps the XR_META_colocation_discovery extension.
Description
Wraps the XR_META_colocation_discovery extension which enables nearby device discovery for colocated multiplayer experiences on Meta Quest devices.
This extension allows devices running the same application to discover each other via Bluetooth without requiring manual lobby selection or network configuration.
Note: This extension is only supported on Meta Quest devices and requires the colocation_discovery extension to be enabled in Project Settings under xr/openxr/extensions/meta/colocation_discovery.
# Check if colocation discovery is supported
if OpenXRMetaColocationDiscoveryExtensionWrapper.is_colocation_discovery_supported():
# Start advertising your session
var session_data = JSON.stringify({"session_id": "my_session", "host": "Player1"}).to_utf8_buffer()
OpenXRMetaColocationDiscoveryExtensionWrapper.start_advertisement(session_data)
# Or start discovering nearby sessions
OpenXRMetaColocationDiscoveryExtensionWrapper.start_discovery()
# Connect to signals
OpenXRMetaColocationDiscoveryExtensionWrapper.openxr_meta_colocation_discovery_discovery_result.connect(_on_discovery_result)
func _on_discovery_result(advertisement_uuid: String, data: PackedByteArray):
var session_info = JSON.parse_string(data.get_string_from_utf8())
print("Found session: ", session_info)
Tutorials
Methods
bool |
is_colocation_discovery_supported ( ) const |
bool |
start_advertisement ( PackedByteArray buffer ) |
bool |
start_discovery ( ) |
bool |
|
bool |
stop_discovery ( ) |
Signals
openxr_meta_colocation_discovery_advertisement_complete ( )
Emitted when advertisement is stopped by the OpenXR runtime (not by user request).
openxr_meta_colocation_discovery_advertisement_failed ( int error_code )
Emitted when an advertisement operation fails. The error_code contains the OpenXR error code.
openxr_meta_colocation_discovery_advertisement_started ( String advertisement_uuid )
Emitted when advertisement successfully starts. The advertisement_uuid uniquely identifies this advertisement session.
openxr_meta_colocation_discovery_advertisement_stopped ( )
Emitted when advertisement is successfully stopped by user request via stop_advertisement.
openxr_meta_colocation_discovery_discovery_complete ( )
Emitted when discovery completes successfully.
openxr_meta_colocation_discovery_discovery_failed ( int error_code )
Emitted when a discovery operation fails. The error_code contains the OpenXR error code.
openxr_meta_colocation_discovery_discovery_result ( String advertisement_uuid, PackedByteArray data )
Emitted when a nearby advertised session is discovered. The advertisement_uuid identifies the discovered session, and data contains the custom session data that was passed to start_advertisement by the advertising device.
Parse the data (typically as JSON) to get session information such as session ID, host name, and available player slots.
openxr_meta_colocation_discovery_discovery_started ( )
Emitted when discovery successfully starts.
openxr_meta_colocation_discovery_discovery_stopped ( )
Emitted when discovery is successfully stopped by user request via stop_discovery.
Method Descriptions
bool is_colocation_discovery_supported ( ) const
Returns true if the colocation discovery extension is supported on the current device, false otherwise.
This should be checked before attempting to use advertisement or discovery features.
bool start_advertisement ( PackedByteArray buffer )
Starts advertising the local session to nearby devices. The buffer contains custom session data (max 1024 bytes) that will be transmitted to discovering devices.
Typically this data contains session information encoded as JSON, such as session ID, host name, and max players.
Returns true if the advertisement request was successfully initiated, false otherwise.
Listen to the openxr_meta_colocation_discovery_advertisement_started signal to know when advertising actually begins, or openxr_meta_colocation_discovery_advertisement_failed if it fails.
Note: Only one advertisement can be active at a time. Call stop_advertisement first if already advertising.
bool start_discovery ( )
Starts discovering nearby advertised sessions. Returns true if the discovery request was successfully initiated, false otherwise.
Listen to the openxr_meta_colocation_discovery_discovery_started signal to know when discovery actually begins, and openxr_meta_colocation_discovery_discovery_result for each discovered session.
Note: Only one discovery operation can be active at a time. Call stop_discovery first if already discovering.
bool stop_advertisement ( )
Stops the current advertisement. Returns true if the stop request was successfully initiated, false otherwise.
Listen to the openxr_meta_colocation_discovery_advertisement_stopped signal to know when advertising actually stops.
bool stop_discovery ( )
Stops the current discovery operation. Returns true if the stop request was successfully initiated, false otherwise.
Listen to the openxr_meta_colocation_discovery_discovery_stopped signal to know when discovery actually stops.