Unity
QAROS ships two Unity packages that stream a Unity scene to AR/VR devices. They carry the C# binding, not the native runtime: the Editor and every player load the runtime of the QAROS installed on the PC, like any other source app.
| Package | Folder | Install when | Depends on |
|---|---|---|---|
com.quaternar.streaming | QarStreaming | Always | Unity Input System 1.7.0, Unity UI 1.0.0 |
com.quaternar.streaming.mrtk | QarStreamingMRTK | Only in MRTK 3 projects | com.quaternar.streaming, Unity Input System 1.7.0, XR Core Utils 2.2.3, MRTK Core 4.0.0-pre.1, MRTK Input 4.0.0-pre.1, MRTK UX Components 4.0.0-pre.1, MRTK Extended Assets 3.0.3 |
QarStreamingis the integration: theQarStreamingandQarDeviceprefabs, stereo camera capture for the built-in render pipeline and URP, a sample scene and the C# binding inlib/windows-x64.QarStreamingMRTKextends it, never replaces it: an MRTK XR rig prefab, MRTK profile and configuration assets, QAROS hands as an MRTK hand subsystem, the QAROS head pose driving theXROrigin, and an MRTK sample scene.
Requirements
- Unity 2022.3 or newer. Tested with 2022.3 and 6000.4.
- Windows x64. The QAROS runtime is built for Windows x64 only.
- Direct3D 11 or Vulkan. In Project Settings > Player > Other Settings, turn off Auto Graphics API for Windows and put Direct3D11 or Vulkan first in the list. Direct3D 12 and OpenGL are not supported. See Graphics APIs for how the two differ.
- The built-in render pipeline or URP.
- QAROS installed on the PC, release or demo (see Installation). The app loads its runtime, joins its Hub and streams to the target apps in its session. Without it, joining fails with "QAROS Hub is not installed on this PC", in the Inspector and the in-game target list; in the Editor a dialog also offers to open the installation guide.
Installation
The Unity ZIP (QAROS Unity <version>.zip, see Installation)
holds both packages, ready to install, plus a short INSTALL.md and the CHANGELOG.md.
- Unzip it to a location you keep. A package added from disk is referenced, not copied: moving or deleting the folder breaks the project.
- MRTK 3 projects only: install the MRTK packages first (see MRTK 3).
- Add the packages in this order. Unity cannot resolve
QarStreamingMRTK's dependency on a local package by itself, so the base package must already be there.QarStreaming/package.jsonQarStreamingMRTK/package.json, only if the project uses MRTK 3
With the Package Manager
- Open your Unity project.
- Open Window > Package Manager.
- Press + and choose Add package from disk....
- Select the package's
package.json.
With the manifest file
Alternatively, add the packages to the project's Packages/manifest.json. The paths are relative
to that file. With the unzipped folder next to the Unity project:
{
"dependencies": {
"com.quaternar.streaming": "file:../../QAROS-Unity-<version>/QarStreaming",
"com.quaternar.streaming.mrtk": "file:../../QAROS-Unity-<version>/QarStreamingMRTK"
}
}
Release and demo
One QAROS Unity <version>.zip serves both flavors: the packages load whichever QAROS is installed
on the PC, release or demo. Switching flavors means installing the other QAROS, not changing the
packages.
The sample scene
Open QarSampleScene from the QarStreaming package's Samples folder. It has one QarStreaming
prefab and a Connect button that calls QarMultiUserStreamingBehaviour.Join.
- Start QAROS on this machine, and a target: a headset player, or a Visualizer receiver.
- Enter Play mode. The app joins the Hub on this PC as a local app; the first time, click Allow in the QAROS approval prompt.
- The scene streams to every reachable target. The target list shows in the game view and in the
QarStreamingInspector.
Prefabs
| Prefab | Role | Contains |
|---|---|---|
QarStreaming | The streaming coordinator, one per scene | QarMultiUserStreamingBehaviour (onboarding, which targets to stream to, render and gesture settings, the device prefab, and runtime settings such as EnableMixer) and QarTargetPickerOverlay (the in-game target list) |
QarDevice | One target's view | QarDeviceBehaviour, a left-eye and a right-eye camera, and optional hand and head visualizers |
QarMultiUserStreamingBehaviour creates a child QarDevice for each target it streams to, named
after the target, and destroys it when streaming to that target stops.
Onboarding
The app joins the Hub's session once; every target is streamed to through that session. The
general flow is in Onboarding and Sessions; in
Unity it is driven by Onboarding on QarMultiUserStreamingBehaviour.
The app joins the Hub on this PC as a local app, with no code. The first time, QAROS asks the user to allow the app (the Unity Editor once for every project opened in it); later starts join silently. Nothing is saved, so every start joins the same way.
- An app QAROS launched joins the same way.
- On a PC whose Hub joined another PC's Hub as a member, the app joins its own PC's Hub the same way and lands in the primary's session.
- To shut the app out, revoke its approval in QAROS.
| Setting | Use |
|---|---|
| Approval Timeout Seconds | How long to wait for the user to allow the app. 0 uses the Hub's default (120 s). |
| Use Unity Graphics Adapter | Creates the session's GPU devices on the adapter Unity renders with (NVIDIA only), so frames need no copy between GPUs. QAR_GPU_ADAPTER_ID in the environment overrides it (see Choosing the GPU). |
| Timeout Seconds | How long to wait for the session after the approval. |
Join() blocks until the Hub answers. When it fails, LastJoinError says why and the target list
offers to join again.
Targets
A target is a target app already in the Hub's session: a HoloLens 2, Meta Quest or Metalens player, the Android streamer, or a Visualizer receiver. The app never invites or starts a device. A target appears in the list once it joined the Hub on its own (see Player Installation to Device), and leaves it when it is gone.
- Stream To All Targets (on by default) streams to every reachable target, including ones that join later.
- Turn it off to pick: only the targets checked in the list are streamed to.
- Each row shows the target's display name, its device type and its state; hover it for the peer ID.
- The list is in the game view (
QarTargetPickerOverlay, immediate-mode GUI, no Canvas needed) and in theQarStreamingInspector in Play mode. Turn the overlay's Visible off, or remove it, to build your own UI on the API below. - A target that fails to connect is tried again every few seconds while it stays picked.
| Member | Does |
|---|---|
Join(), IsJoined, LastJoinError | Joins the Hub and starts listing targets; whether it did; why not |
Targets | The target list (QarStreamTarget: Id, DisplayName, Category, DeviceId, DeviceFamily, DeviceName, DeviceLabel, Presence, IsOnline, IsReachable, Selected, Device, ConnectionState, LastError) |
TargetsChanged | Raised on the main thread when a target joins, leaves, changes or is picked |
StreamToAllTargets | Stream to every reachable target, or only the picked ones |
SetTargetSelected(PeerId, bool), IsStreamedTo(target) | Picks a target; whether it is streamed to |
Leave() | Stops streaming to every target and stops listing them |
App volume
Every target shows the scene in one app volume, identified by App Volume Common Name (the product name when empty), so all users see the same scene placed once. Joining again gets the same volume back with its placement.
Gestures
Enable Gestures turns QAROS app volume gestures on or off for the targets' hands. Keep it on for normal QAROS gesture handling. Turn it off when another input stack consumes the hands.
GUI panels and served panels
The components wrap streaming only. For GUI panels, including pages your app serves itself, use the C# API on the session the components joined:
using Quaternar.Qaros;
using QuaternarStreaming;
Session session = QarSession.Current; // null until a QAROS component has joined the hub
var bundle = session.PanelContent.PublishDirectory("ui", Application.streamingAssetsPath + "/panels");
QarSession.Currentis the one session of the process; never dispose it, the components own it.session.GuiPanelscreates and changes panels (GuiPanelOptions.ServedContentfor a served page),session.PanelContentpublishes the files and carries the page's messages. Both work as described in Custom GUI Panels.- Put panel pages under
StreamingAssetsso a player build ships them as plain files.
Naming a panel
There is no panel component, so a panel's name is set in code, not in the Inspector. The display name is the label the mixer shows above the panel; the common name is its stable identity.
var options = new GuiPanelOptions("inspector.myapp.example.com") // stable identity, ASCII
{
DisplayName = "🎬 Inspector", // label shown above the panel, emoji allowed
};
GuiPanelId panelId = session.GuiPanels.GetOrCreate(options).ValueOrThrow();
Result<Unit> renamed = session.GuiPanels.ChangeDisplayName(panelId, "Settings");
if (renamed.Info.StatusCode == StatusCode.GuiPanelDisplayNameInvalid)
Debug.LogWarning("Panel name refused: " + renamed.Info.Message);
- The name follows the display name rules:
one line of at most 64 characters, counted as Unicode code points, not C#
chars (one emoji is twochars but one character). - Line breaks, other control characters and bidirectional formatting characters are refused with
StatusCode.GuiPanelDisplayNameInvalid, both on create and on rename. A refused name is never shortened, and a refused rename keeps the previous name. - A C# string can hold a lone surrogate (half of an emoji), which has no UTF-8 form. It reaches
QAROS as U+FFFD (�) and is accepted, so cut a name only at whole characters, for example with
StringInfo. - Show the name in your own Unity UI from
GuiPanel.DisplayNamein the panel updates, never from the common name.
Coordinate spaces
The views and hands a target's device receives are in its app volume's app content space, in OpenXR convention: right-handed, +Y up, -Z forward, in app units. The Unity world is the app content root.
QarDeviceBehaviour.ToUnityPosition,ToUnityRotation,ToUnityLinearVelocityandToUnityAngularVelocityconvert to Unity's left-handed space. They only flip handedness.LeftHandJointsandRightHandJointsstay in app content space: convert them with those methods.- Never apply the app volume's pose or scale on top: the Unity world already is the app content space.
Transparency
QarDeviceBehaviour declares what its color's alpha means with the stream, through Alpha Mode
in the Inspector. The mixer composites the stream by it
(Transparency).
| Alpha Mode | Use when |
|---|---|
Premultiplied (default) | The cameras clear to transparent black, so translucent materials, soft edges and glow are composited over what is behind the app volume |
Straight | Your color is not multiplied by its alpha (for example a custom pass writes straight alpha). QAROS premultiplies it before sending |
Opaque | Post-processing or a custom pass overwrites the alpha channel. With Premultiplied such content would turn transparent |
Unspecified | Declares nothing: the mixer draws the stream opaque unless the operator enables alpha for undeclared streams |
- Unity's transparent materials write no depth. They show at the middle of the app volume along each view ray, so they occlude there and move without parallax.
- Opaque materials must leave alpha at 1. A shader that writes a lower alpha on an opaque surface makes it translucent in the mixer.
MRTK 3
QarStreamingMRTK puts QAROS behind MRTK 3: the QAROS head pose drives the MRTK rig and the QAROS
hands become MRTK hands.
- Install MRTK first with the Mixed Reality Feature Tool. The Unity Package Manager may not offer the MRTK versions the package needs.
- It uses the first streamed target only. To keep a hand from being handled twice, by MRTK and by QAROS app volume gestures, it turns gestures off for that target's device at runtime. The Enable Gestures value in the Inspector does not change. Further targets stream as usual.
- The MRTK sample scene
QarSampleSceneMrtkhas a debug Connect button built with MRTK UX Components and MRTK Extended Assets. The integration itself does not use those two packages; only that button does.
Player builds
A player build carries no native runtime: like the Editor, it loads the runtime of the QAROS
installed on the PC where it runs. Install QAROS there; do not copy a qar-streaming-c.dll next to
the player, since a copy beside the binding would be loaded instead of the installed one. A
player or Editor started with QAR_INSTANCE set (a QAROS development hub sets it for the apps it
starts) loads the runtime of that instance instead, and fails to load when that instance has none;
the lookup is the one in Authoring a Language Binding.
Graphics APIs
The package streams under Direct3D 11 and under Vulkan, in the Editor and in player builds.
- Any other graphics API is refused. Under Direct3D 12 or OpenGL the runtime does not start:
it throws a
NotSupportedExceptionthat names the API, and nothing streams. - Vulkan needs
QarUnityGraphics.dll, which the package ships inlib/windows-x64. It is the one native plugin Unity loads itself, at startup, so that it can prepare Unity's Vulkan device for sharing frames. Keep Load on startup set in its import settings. Without it a Vulkan player cannot stream, and the runtime refuses to start with aNotSupportedExceptionthat says why. - Under Vulkan, cap the frame rate instead of using VSync. A Vulkan frame is shown only after
Unity's render thread has handed it over. Show Vulkan Frames On Worker, on
QarDeviceand on by default, waits for that hand-off on a worker thread instead of the next frame.- In our measurements a Vulkan player capped at 60 fps with
Application.targetFrameRatestreamed at the Direct3D 11 rate, with frames within 2 ms as fresh. - Under VSync it streamed a little over half the Direct3D 11 rate (46 against 79 per second on a
165 Hz display), so set
QualitySettings.vSyncCountto 0 and cap withtargetFrameRate. - Turning the option off shows every frame from the main thread, which streams about half as many frames at a cap. Leave it on unless you need that fallback.
- With the option on, the package can move the eye cameras, hands and headset model just before
the first eye camera renders. A script reading them in
LateUpdatemay see the previous frame's pose.
- In our measurements a Vulkan player capped at 60 fps with