Start/Stop spatial mapping via script in unity

Hello,

I am using a meta quest 2 and the zed unity package with a zed 2i camera. I am trying to start spatial mapping when the left trigger is pressed on controllers and then stop when the right trigger is pressed. I followed the tutorial for AR passthrough to get the camera feed onto the quest but am quite confused on how to add the spatial mapping functionality outside of what can be done via the inspector. Are there examples of this/can anyone provide examples for how they achieved something similar via code? I reviewed the spatial mapping example in the unity package but that seems to use the inspector and not a stand alone script to start/stop spatial mapping. I have tried calling zedManager.StartSpatialMapping() but that gives me an empty ZED mesh holder game object. Are there additional setup steps that I am missing?

Thanks!

Hi,

I think it should be enough.

The code behind the “start spatial mapping” button in the inspector can be found here : zed-unity/ZEDCamera/Assets/ZED/Editor/Scripts/ZEDCameraEditor.cs at master · stereolabs/zed-unity · GitHub
and it’s basically what you are doing.

I’ll perform some tests on my side to see what I’m missing here.

Here is my code & hierarchy currently. Right now I am just trying to start spatial mapping when zed is ready (without trigger press). I have the ScanManager script attached to an empty game object (also called ScanManager). When I enter play mode the mesh holder appears but is always empty. I do not enter the else statement.


Hi,

It seems that trying to start the spatial mapping on the OnZEDReady callback fails. I think something is not yet initialized, I’m looking into it.

However, if you bind the start of the spatial mapping on a key event, and trigger it manually, it’s working fine with the same code.

1 Like

Thank you, that works!