** Before meshing begins, make sure to call SetCustomMeshBlockRequests to set the callback, as there is a known issue currently that could cause a crash If this callback is not set, even if it is not being used. An example of how to do this is shown in the meshing sample provided.*
I looked at the example and did exactly how its done by setting the callback in the awake method on my meshing controller script. Everything is pretty much the exact same as the example but yet it still doesn't work.
When I make a build, nothing such as like my normal UIs etc are showing. If I turn on the objects that does the meshing with a delay, all the UI will disappear. I simply believe the app is just crashing.
If I run it in device simulator, Unity crashes.
If I completely disable Meshing, everything runs fine. However I need Meshing for my app so without this its pretty useless.
Unity Editor version: 2022.2.0b14 ML2 OS version: 1.1.0-dev2 MLSDK version: 1.1.0-dev2 Host OS: (Windows/MacOS): Windows 11
@jc1 Can you try removing any custom scripts that enable meshing and try to do the following:
1.Create Mesh Root
Create a new GameObject and name it "Mesh Root"
Make sure that it is positioned at 0,0,0 and has the scale set to 1,1,1
2.Create Mesh Graphic
Create an empty game object and name it "Mesh"
2.Add A mesh Renderer Component to it
3.Create a new material and assign it under the Materials Tab
Add a Mesh Collider (if you are using collisions)
Add a Mesh filter
Drag it into your assets folder to create a prefab
2.Configure the Meshing Subsystem Component
Next, Create a new GameObject and name it "Meshing Subsystem"
Add the Meshing Subsystem Component to the "Meshing Subsystem" GameObject
Set the scale of the "Meshing Subsystem" to 10,10,10
Then Set the Mesh Parent to the Mesh Root GameObject
Set the Mesh Prefab to the Mesh prefab that you created in the previous step
3.Permissions
After the components are configured, make sure you have enabled Spatial Mapping in the Permission Settings.
Since this is a dangerous permission, you will need to request it at runtime. To do this create a new script and name it something like "MeshingPermissionRequester"
Add it to the Mesh Root GameObject
Open the script and add the following line of code
using UnityEngine;
using UnityEngine.XR.MagicLeap;
public class MeshingPermissionRequester : MonoBehaviour
{
private MeshingSubsystemComponent _meshManager;
private readonly MLPermissions.Callbacks _permissionCallbacks = new MLPermissions.Callbacks();
private void Awake()
{
_permissionCallbacks.OnPermissionGranted += OnPermissionGranted;
_permissionCallbacks.OnPermissionDenied += OnPermissionDenied;
}
private void OnDestroy()
{
_permissionCallbacks.OnPermissionGranted -= OnPermissionGranted;
_permissionCallbacks.OnPermissionDenied -= OnPermissionDenied;
}
private void Start()
{
_meshManager = FindObjectOfType<MeshingSubsystemComponent>();
if (_meshManager == null)
{
Debug.LogError("Failed to find MeshingSubsystemComponent in scene. Disabling Script");
enabled = false;
}
else
{
_meshManager.enabled = false;
}
MLPermissions.RequestPermission(MLPermission.SpatialMapping, _permissionCallbacks);
}
private void OnPermissionGranted(string permission)
{
_meshManager.enabled = true;
}
private void OnPermissionDenied(string permission)
{
Debug.LogError($"Failed to create Mesh Subsystem due to missing or denied {MLPermission.SpatialMapping} permission. Please add to manifest. Disabling script.");
enabled = false;
}
}
I implemented it as you shared but it did not work. At first, nothing was displayed when the MeshingSubsystemComponent was active. The next time I ran it with the MeshingSubsystemComponent deactivated, nothing was displayed at the time I executed _meshManager.enabled = true; in OnPermissionGranted.
The mesh is of course invisible, but I have added XR Rig controllers and also displayed the UI, but these are not visible at all. If I intentionally comment out the _meshManager.enabled = true process, the red lines and UI of the XR Rig controllers show up fine.
I have previously posted about meshing problems, but I am experiencing the same problem.
Hi, this doesn't work for me either, I have the same problem but only when I am using MRTK.
Also I added the following piece of code:
In Awake:
MeshingSubsystem.Extensions.MLMeshing.Config.SetCustomMeshBlockRequests(CustomBlockRequests);
And the method
MeshingSubsystem.Extensions.MLMeshing.MeshBlockRequest[] CustomBlockRequests(MeshingSubsystem.Extensions.MLMeshing.MeshBlockInfo[] blockInfos)
{
var blockRequests = new MeshingSubsystem.Extensions.MLMeshing.MeshBlockRequest[blockInfos.Length];
for (int i = 0; i < blockInfos.Length; ++i)
{
var blockInfo = blockInfos[i];
var distanceFromCamera = Vector3.Distance(_camera.transform.position, blockInfo.pose.position);
if (distanceFromCamera > 1)
blockRequests[i] = new MeshingSubsystem.Extensions.MLMeshing.MeshBlockRequest(blockInfo.id, MeshingSubsystem.Extensions.MLMeshing.LevelOfDetail.Minimum);
else
blockRequests[i] = new MeshingSubsystem.Extensions.MLMeshing.MeshBlockRequest(blockInfo.id, MeshingSubsystem.Extensions.MLMeshing.LevelOfDetail.Maximum);
}
return blockRequests;
}
but the crash still occurs however the issues is not 100% repro, I would say 8/10. I have a feeling this has to do with the fact that I am using MRTK as it works fine in the example scene which does not use MRTK and the code that I am using is exactly the same which also includes that example you provided.
I then tried to use spatial mapping directly form the MRTK toolkit module and this also does not work
@jc1
cc @kbabilinski
I have added the Awake process you shared and verified it. The event of nothing being displayed was improved, but no mesh was generated at all in the crucial space. 1.1.0-dev2 makes Meshing risky to use, I think.
Hey, thanks for checking it. Yer at first I though it was due to MRTK in conjunction but I tried it without MRTK and I am getting the issue but its not 100% repro (it worked only about 2/10 times) which then made me think it could be a script execution order issue so I did some tweaks to that but I am still getting the issue.
I have also encountered the issue directly within the example scene provided by ML2 without any modification. (again the issue was not 100% repro)
Due to this my team have reverted all our current project to dev1 and OS back to dev1. Meshing for dev2 is just not stable, hopefully the next update will fix this.