Skip to main content
Version: 12 Dec 2024

Best Practices and Troubleshooting

Including ML Spectator Prefabs in Scenes

The ML Spectator prefab only needs to be included once in your project. Even if your project has multiple scenes, you only need one instance of the prefab. However, in order to ensure that the ML Spectator utilities function from launch, the prefab must be included in the first scene that is loaded when your application starts up. Once the prefab has been called it will keep running until the application is closed. There is no need to include the prefab in every scene loaded as the utilities are inherited between scenes and not destroyed when changing scenes or application states.

Enabling ML Spectator Utilities

By default, the ML Spectator utilities are not enabled. Within the inspector, on the ML Spectator prefab, there is an option for Auto Enable. It is suggested that this option not be selected for public builds. To enable ML Spectator at runtime, include a toggleable UI element to call MLSpectator.Instance.Enable() and MLSpectator.Instance.Disable(). There is also a toggle function available: MLSpectator.lnstance.Toggle(). If Auto Enable is used, you should include a privacy notification stating that ML Spectator is active and that sessions could be joined and recorded.

Special Lighting Modes

If the scene uses a single light attached to the Main Camera prefab in order to light the scene, then ML Spectator may display the AR content with inconsistent lighting. In this case, enable the Control Scene Lights option in the ML Spectator prefab. However, if your application lights the scene globally or with baked-in lights as a part of the scene, then ML Spectator will function and display the AR content as expected.

ML Spectator Viewer Lens Prefab When Controlling Special Scene Lighting

Inside of the ML Spectator prefab is an option for a lens prefab that represents the lens of the camera of the mobile device being used in a session. This can be used via the ML2 user to diagnose the quality of the synchronization when connected. It is very small, otherwise unneeded, and does not need to be disabled or changed. However, if the option Control Scene Lights is enabled, this prefab is required because it includes a light which takes the place of the Main Camera light when rendering AR content to display on the mobile device.

In Editor Preview

There is an option to preview the ML Spectator view from within the Unity editor for debug purposes. Normally this will not cause any interactions with a built project when running. However, if your project is designed to be controlled via the editor when running on the ML2 headset, this option will interrupt the displayed scene when entering Play mode. In order to avoid this interaction, disable this option in the prefab settings.

It is recommended that you use the Performant Quality setting in your project settings to reduce visual artifacts. Regardless of the quality settings that are selected, ensure that the URP is the render pipeline selected.

The Intermediate Texture mode should be set to Always (located under Compatibility in your URP settings) to ensure correct render order for the ML Spectator rendering camera. If set to Auto, the layer order of objects can shift and produce unwanted results. Setting Intermediate Texture to Always ensures that secondary scene cameras operating outside of a scriptable render pass have proper depth projection and layer order.

Can the ML Spectator utility work in the editor?

Yes, the ML Spectator plugin is functional in the editor on Windows and Mac computers. For the best experience, make sure that the editor can run in the background. This can be done by checking Edit > Project Settings… > Player > Settings for Windows, Mac, Linux > Resolution and Presentation > Run In Background.

Enable Marker Scanning (ML Unity package v2.x.x+)

The ML Spectator plugin is using the legacy Magic Leap API to manage marker tracking. In order to use the ML Spectator plugin with OpenXR support (version 2.x.x and later), you must enable Perception Snapshots. This is located under Project Settings > XR Plug-in Management > OpenXR > Magic Leap 2 Support. Open the settings for Magic Leap 2 Support by clicking on the gear icon. Perception Snapshots is listed under Feature Settings.

ML Spectator plugin not running in editor

The ML Spectator plugin is supposed to run in the Unity editor, however it won't run if Vulcan or OpenGL is set as the graphics backend. The ML Spectator plugin only works when DirectX is set as the graphics backend on a Windows Machine or Metal for Mac OS based machines.