# SpatialAwareness example scenes doesn't work

**URL:** https://forum.magicleap.cloud/t/spatialawareness-example-scenes-doesnt-work/1817
**Category:** Unity Development
**Tags:** development
**Created:** [May 1, 2023, 12:19pm UTC](https://forum.magicleap.cloud/t/spatialawareness-example-scenes-doesnt-work/1817 "2023-05-01T12:19:57Z")
**Posts on this page:** 8
**Page:** 1

<div class="post-metadata">

### Author: ![TheMunk](https://avatars.discourse-cdn.com/v4/letter/t/c4cdca/32.png) [@TheMunk](https://forum.magicleap.cloud/u/TheMunk)
#### Post date: [May 1, 2023, 12:19pm UTC](https://forum.magicleap.cloud/t/spatialawareness-example-scenes-doesnt-work/1817/1 "2023-05-01T12:19:57Z")

</div>

After updating to 1.5.0 our spatial awareness all went green, and after trying to debug, we decided to try and implement using MRTK spatial awareness (as this wasn't available when we initially set up the project).  
But just building the sample scene doesn't work. A bunch of errors (seems like the meshparent gets destroyed), and initialization order (permission request before OnEnable) also gives errors.  
Also, there's UI in the scene but he MRTK profile doesn't include any Input Profile.

After fixing all of these errors in the MaigcLeapSpatialMeshObserver, we're still getting this last error, (and the mesh is still not showing up);

**Unity Editor version** :  
2022.2.6  
**ML2 OS version** :  
1.2.0  
**MLSDK version** :  
1.6.0

```auto
2023-05-01 12:13:25.503 28819 28848 Error Unity NotSupportedException: To marshal a managed method, please add an attribute named 'MonoPInvokeCallback' to the method definition. The method we're attempting to marshal is: UnityEngine.XR.MagicLeap.MLAutoAPISingleton`1[[UnityEngine.XR.MagicLeap.MLPermissions, MagicLeap.SDK, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null]]::OnPerceptionShutdown
2023-05-01 12:13:25.503 28819 28848 Error Unity at UnityEngine.XR.MagicLeap.MLAutoAPISingleton`1[T].Initialize () [0x0005b] in .\Submodules\MagicLeapSDK\com.magicleap.unitysdk\Runtime\Common\MLAutoAPISingleton.cs:56 
2023-05-01 12:13:25.503 28819 28848 Error Unity at UnityEngine.XR.MagicLeap.MLLazySingleton`1[T].get_Instance () [0x00021] in .\Submodules\MagicLeapSDK\com.magicleap.unitysdk\Runtime\Common\MLLazySingleton.cs:31 
2023-05-01 12:13:25.503 28819 28848 Error Unity at UnityEngine.XR.MagicLeap.MLPermissions.RequestPermission (System.String permission, UnityEngine.XR.MagicLeap.MLPermissions+Callbacks callbacks) [0x00000] in .\Submodules\MagicLeapSDK\com.magicleap.unitysdk\Runtime\APIs\Permissions\MLPermissions.cs:55 
2023-05-01 12:13:25.503 28819 28848 Error Unity at MagicLeap.MRTK.SpatialAwareness.MagicLeapSpatialMeshObserver.Enable ()

```

---

<div class="post-metadata">

### Author: ![TheMunk](https://avatars.discourse-cdn.com/v4/letter/t/c4cdca/32.png) [@TheMunk](https://forum.magicleap.cloud/u/TheMunk)
#### Post date: [May 1, 2023, 12:43pm UTC](https://forum.magicleap.cloud/t/spatialawareness-example-scenes-doesnt-work/1817/2 "2023-05-01T12:43:57Z")

</div>

Update:  
We have the same error in the non-MRTK example scene - build from the same project (we have both example packages in our main project).  
Through that UI I can re-open the meshing sample scene, and when this is done, the spatial mesh starts up correctly.

---

<div class="post-metadata">

### Author: ![ababilinski](https://sea1.discourse-cdn.com/flex019/user_avatar/forum.magicleap.cloud/ababilinski/32/79_2.png) [@ababilinski](https://forum.magicleap.cloud/u/ababilinski)
#### Post date: [May 2, 2023, 12:18am UTC](https://forum.magicleap.cloud/t/spatialawareness-example-scenes-doesnt-work/1817/3 "2023-05-02T00:18:35Z")

</div>

Hi @TheMunk, Is the example scene the same as the one in the MagicLeap\_Examples project?

---

<div class="post-metadata">

### Author: ![TheMunk](https://avatars.discourse-cdn.com/v4/letter/t/c4cdca/32.png) [@TheMunk](https://forum.magicleap.cloud/u/TheMunk)
#### Post date: [May 2, 2023, 6:09am UTC](https://forum.magicleap.cloud/t/spatialawareness-example-scenes-doesnt-work/1817/4 "2023-05-02T06:09:30Z")

</div>

Yes. We fresh import both example packages on every SDK update.

---

<div class="post-metadata">

### Author: ![TheMunk](https://avatars.discourse-cdn.com/v4/letter/t/c4cdca/32.png) [@TheMunk](https://forum.magicleap.cloud/u/TheMunk)
#### Post date: [May 2, 2023, 8:53am UTC](https://forum.magicleap.cloud/t/spatialawareness-example-scenes-doesnt-work/1817/5 "2023-05-02T08:53:36Z")

</div>

After changing some stuff around, I seem to have gotten something working, but only if we start up directly into a scene with meshing enabled.  
If not, we get this native crash;  
[tombstone\_00.txt](https://forum.magicleap.cloud/uploads/short-url/zd5J8WG6h4MRIWZ4PMTde0aUVSF.txt) (368.7 KB)  
[tombstone\_01.txt](https://forum.magicleap.cloud/uploads/short-url/3mG7Qv28CFxPNZOR0vRrVoltXTZ.txt) (370.5 KB)  
[tombstone\_02.txt](https://forum.magicleap.cloud/uploads/short-url/2evg3DIkNqIxDHUWNETYzj5n33p.txt) (371.1 KB)

EDIT:  
Seems to be the old "SetCustomMeshBlockRequests" bug - now everything seems to work correctly again.  
Although still getting some occasional errors in the log;

```auto
2023-05-02 09:01:55.130 24259 24281 Error com.Laerdal.MRTKTest_0_1_20_pre1 leapcore/frameworks/perception/services/meshing_manager/client/src/client.cpp(151) GetMeshingDataResponse():
2023-05-02 09:01:55.130 24259 24281 Error com.Laerdal.MRTKTest_0_1_20_pre1 ERR: [stack trace begin]
2023-05-02 09:01:55.130 24259 24281 Error com.Laerdal.MRTKTest_0_1_20_pre1 #00 pc 0000000000014baa /system/lib64/libml_meshing_manager_client.so (ml::perception::meshing_manager::Client::GetMeshingDataResponse(unsigned long, ml::pil::ss::MeshingMesh*)+1914)
2023-05-02 09:01:55.130 24259 24281 Error com.Laerdal.MRTKTest_0_1_20_pre1 #01 pc 0000000000017bf3 /system/lib64/libml_perception_meshing.so (ml::perception::datasources::BinderMeshingDataSource::GetResponse(unsigned long const&, ml::pil::ss::MeshingMesh*) const+179)
2023-05-02 09:01:55.130 24259 24281 Error com.Laerdal.MRTKTest_0_1_20_pre1 #02 pc 0000000000012804 /system/lib64/libml_perception_meshing.so (ml::perception::components::meshing::Meshing::GetMeshingDataResponse(unsigned long, ml::pil::ss::MeshingMesh*)+164)
2023-05-02 09:01:55.130 24259 24281 Error com.Laerdal.MRTKTest_0_1_20_pre1 #03 pc 0000000000082fc0 /system/lib64/libperception.magicleap.so (MLMeshingGetMeshResult+272)
2023-05-02 09:01:55.130 24259 24281 Error com.Laerdal.MRTKTest_0_1_20_pre1 #04 pc 000000000019b47d /data/app/com.Laerdal.MRTKTest_0_1_20_pre1-qnPeBWQJjg_OKhL_n9hHmg==/lib/x86_64/libml_sdk_loader.so (_ZN9DelayCallI10perception31MLMeshingGetMeshResultDelayCalliJmmP13MLMeshingMeshEEclEmmS3_+77)
2023-05-02 09:01:55.130 24259 24281 Error com.Laerdal.MRTKTest_0_1_20_pre1 #05 pc 000000000019a96b /data/app/com.Laerdal.MRTKTest_0_1_20_pre1-qnPeBWQJjg_OKhL_n9hHmg==/lib/x86_64/libml_sdk_loader.so (_Z26MLMeshingGetMeshResultShimIJmmP13MLMeshingMeshEEiDpT_+123)
2023-05-02 09:01:55.130 24259 24281 Error com.Laerdal.MRTKTest_0_1_20_pre1 #06 pc 000000000019a8e4 /data/app/com.Laerdal.MRTKTest_0_1_20_pre1-qnPeBWQJjg_OKhL_n9hHmg==/lib/x86_64/libml_sdk_loader.so (MLMeshingGetMeshResult+36)
2023-05-02 09:01:55.130 24259 24281 Error com.Laerdal.MRTKTest_0_1_20_pre1 #07 pc 00000000000c4a6e /data/app/com.Laerdal.MRTKTest_0_1_20_pre1-qnPeBWQJjg_OKhL_n9hHmg==/lib/x86_64/libMagicLeapXrProvider.so (MeshingSubsystem::ProcessPendingBatchRequest()+94)
2023-05-02 09:01:55.130 24259 24281 Error com.Laerdal.MRTKTest_0_1_20_pre1 #08 pc 00000000000c44bf /data/app/com.Laerdal.MRTKTest_0_1_20_pre1-qnPeBWQJjg_OKhL_n9hHmg==/lib/x86_64/libMagicLeapXrProvider.so (MeshingSubsystem::GetMeshInfos(UnityXRMeshInfoAllocator*)+575)
2023-05-02 09:01:55.130 24259 24281 Error com.Laerdal.MRTKTest_0_1_20_pre1 #09 pc 00000000000c23b4 /data/app/com.Laerdal.MRTKTest_0_1_20_pre1-qnPeBWQJjg_OKhL_n9hHmg==/lib/x86_64/libMagicLeapXrProvider.so (_ZZN16MeshingSubsystem10InitializeEPvS0_ENK3$_0clES0_S0_P24UnityXRMeshInfoAllocator+36)
2023-05-02 09:01:55.130 24259 24281 Error com.Laerdal.MRTKTest_0_1_20_pre1 #10 pc 00000000000c2384 /data/app/com.Laerdal.MRTKTest_0_1_20_pre1-qnPeBWQJjg_OKhL_n9hHmg==/lib/x86_64/libMagicLeapXrProvider.so (_ZZN16MeshingSubsystem10InitializeEPvS0_EN3$_08__invokeES0_S0_P24UnityXRMeshInfoAllocator+36)
2023-05-02 09:01:55.130 24259 24281 Error com.Laerdal.MRTKTest_0_1_20_pre1 #11 pc 00000000018c2434 /data/data/com.Laerdal.MRTKTest_0_1_20_pre1/pram-shadow-files/lib/libunity.so (_ZN18XRMeshingSubsystem12GetMeshInfosEP13dynamic_arrayI8MeshInfoLm0EE+90)
2023-05-02 09:01:55.130 24259 24281 Error com.Laerdal.MRTKTest_0_1_20_pre1 #12 pc 00000000018c3706 /data/data/com.Laerdal.MRTKTest_0_1_20_pre1/pram-shadow-files/lib/libunity.so (XRMeshingSubsystem::GetMeshInfosAsList(ScriptingObjectPtr)+82)
2023-05-02 09:01:55.130 24259 24281 Error com.Laerdal.MRTKTest_0_1_20_pre1 #13 pc 0000000000b5ec83 /data/data/com.Laerdal.MRTKTest_0_1_20_pre1/pram-shadow-files/lib/libunity.so (XRMeshSubsystem_CUSTOM_GetMeshInfosAsList(ScriptingBackendNativeObjectPtrOpaque*, ScriptingBackendNativeObjectPtrOpaque*)+150)
2023-05-02 09:01:55.130 24259 24281 Error com.Laerdal.MRTKTest_0_1_20_pre1 #14 pc 000000000e86db35 /data/data/com.Laerdal.MRTKTest_0_1_20_pre1/pram-shadow-files/lib/libil2cpp.so (XRMeshSubsystem_GetMeshInfosAsList_m72D6DDE116C761283E51B90D4EBC50D59C395917+69)
2023-05-02 09:01:55.130 24259 24281 Error com.Laerdal.MRTKTest_0_1_20_pre1 #15 pc 000000000e86da3c /data/data/com.Laerdal.MRTKTest_0_1_20_pre1/pram-shadow-files/lib/libil2cpp.so (XRMeshSubsystem_TryGetMeshInfos_m05F584066A873F286C16B99A929C4B3B9AB58FD2+748)
2023-05-02 09:01:55.130 24259 24281 Error com.Laerdal.MRTKTest_0_1_20_pre1 #16 pc 0000000006648122 /data/data/com.Laerdal.MRTKTest_0_1_20_pre1/pram-shadow-files/lib/libil2cpp.so (MeshingSubsystemComponent_Update_mF20690A4624CC450EA1F2A42349BDA696F641977+2818)
2023-05-02 09:01:55.130 24259 24281 Error com.Laerdal.MRTKTest_0_1_20_pre1 #17 pc 00000000060bacd9 /data/data/com.Laerdal.MRTKTest_0_1_20_pre1/pram-shadow-files/lib/libil2cpp.so (_Z65RuntimeInvoker_TrueVoid_t4861ACF8F4594C3437BB48B6E56783494B843915PFvvEPK10MethodInfoPvPS4_S4_+41)
2023-05-02 09:01:55.130 24259 24281 Error com.Laerdal.MRTKTest_0_1_20_pre1 #18 pc 000000000f00bc7c /data/data/com.Laerdal.MRTKTest_0_1_20_pre1/pram-shadow-files/lib/libil2cpp.so (il2cpp::vm::Runtime::InvokeWithThrow(MethodInfo const*, void*, void**)+92)
2023-05-02 09:01:55.130 24259 24281 Error com.Laerdal.MRTKTest_0_1_20_pre1 #19 pc 000000000f00bbb9 /data/data/com.Laerdal.MRTKTest_0_1_20_pre1/pram-shadow-files/lib/libil2cpp.so (il2cpp::vm::Runtime::Invoke(MethodInfo const*, void*, void **, Il2CppException** )+217)
2023-05-02 09:01:55.130 24259 24281 Error com.Laerdal.MRTKTest_0_1_20_pre1 #20 pc 000000000f0e23ec /data/data/com.Laerdal.MRTKTest_0_1_20_pre1/pram-shadow-files/lib/libil2cpp.so (il2cpp_runtime_invoke+44)
2023-05-02 09:01:55.130 24259 24281 Error com.Laerdal.MRTKTest_0_1_20_pre1 #21 pc 00000000012f82d
2023-05-02 09:01:55.130 24259 24281 Error com.Laerdal.MRTKTest_0_1_20_pre1 leapcore/frameworks/perception/services/meshing_manager/client/src/client.cpp(363) FreeResourcePrivate():
2023-05-02 09:01:55.130 24259 24281 Error com.Laerdal.MRTKTest_0_1_20_pre1 ERR: exception: [Meshing] Query handle not found

```

Still have no idea what i changed, so sorry I can't provide more information.

---

<div class="post-metadata">

### Author: ![TheMunk](https://avatars.discourse-cdn.com/v4/letter/t/c4cdca/32.png) [@TheMunk](https://forum.magicleap.cloud/u/TheMunk)
#### Post date: [May 3, 2023, 7:37am UTC](https://forum.magicleap.cloud/t/spatialawareness-example-scenes-doesnt-work/1817/6 "2023-05-03T07:37:04Z")

</div>

Alright we're still getting the marshal errors whenever we request permissions;

```auto
2023-05-03 07:35:07.610 28688 28710 Error Unity NotSupportedException: To marshal a managed method, please add an attribute named 'MonoPInvokeCallback' to the method definition. The method we're attempting to marshal is: UnityEngine.XR.MagicLeap.MLAutoAPISingleton`1[[UnityEngine.XR.MagicLeap.MLPermissions, MagicLeap.SDK, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null]]::OnPerceptionShutdown
2023-05-03 07:35:07.610 28688 28710 Error Unity at UnityEngine.XR.MagicLeap.MLPermissions.RequestPermission (System.String permission, UnityEngine.XR.MagicLeap.MLPermissions+Callbacks callbacks) [0x00000] in .\Submodules\MagicLeapSDK\com.magicleap.unitysdk\Runtime\APIs\Permissions\MLPermissions.cs:55 
2023-05-03 07:35:07.610 28688 28710 Error Unity at SimplePermissionGuaranteer.Awake () [0x00064] in C:\work\magicleap-ann

```

Which doesn't make any sense, since the MLAutoAPISingleton looks fine;

```auto
[AOT.MonoPInvokeCallback(typeof(MagicLeapXrProviderNativeBindings.CallOnPerceptionShutdownDelegate))]
private static void OnPerceptionShutdown() => Instance.StopInternal();

```

---

<div class="post-metadata">

### Author: ![TheMunk](https://avatars.discourse-cdn.com/v4/letter/t/c4cdca/32.png) [@TheMunk](https://forum.magicleap.cloud/u/TheMunk)
#### Post date: [May 3, 2023, 9:00am UTC](https://forum.magicleap.cloud/t/spatialawareness-example-scenes-doesnt-work/1817/7 "2023-05-03T09:00:51Z")

</div>

UPDATE:  
It seems like some build settings will trigger this error.  
I think its the IL2CPP code generation when set to "Faster (smaller) builds" instead of "Faster runtime" or it might be the incremental "patch and run" option in unity. Or maybe the combination.

---

<div class="post-metadata">

### Author: ![sengelman](https://sea1.discourse-cdn.com/flex019/user_avatar/forum.magicleap.cloud/sengelman/32/11_2.png) [@sengelman](https://forum.magicleap.cloud/u/sengelman)
#### Post date: [May 5, 2023, 3:53pm UTC](https://forum.magicleap.cloud/t/spatialawareness-example-scenes-doesnt-work/1817/8 "2023-05-05T15:53:24Z")

</div>

@TheMunk , have you tried importing this into your project? It will set your project up with the correct options, eliminating any possible error of manually clicking things in the UI? It may help: [Magic Leap Setup Tool | Integration | Unity Asset Store](https://assetstore.unity.com/packages/tools/integration/magic-leap-setup-tool-194780)
