I am currently trying to create an app where the I can have physics objects collide with real world entities (floor, walls, tables, etc.) and I am having trouble using the meshing system. I don’t have any errors or warnings and the application is able to run fine, but upon starting the application, all physics objects just fall through the floor and disappear.
I did make sure that my project has the spatial_mapping feature and meshing subsystem features enabled. Here’s all the components and scripts that I have in my project that should be related to the meshing.
It’s hard to say what could be causing this but your setup looks correct at a glance.
My initial suspicion is something is silently failing in the AddCollider function, like the mesh inside meshFilter is still null when you try to access it.
I would try adding some safety checks and logs to see if everything executes as expected.
private void AddCollider(MeshFilter meshFilter)
{
if (meshFilter == null || meshFilter.sharedMesh == null)
return; // Don't try to add collider if mesh hasn't been generated yet
Debug.Log($"Assigning collider to mesh: {meshFilter.sharedMesh?.name ?? "NULL"}");
var collider = meshFilter.GetComponent<MeshCollider>();
if (collider == null)
collider = meshFilter.gameObject.AddComponent<MeshCollider>();
collider.sharedMesh = meshFilter.sharedMesh;
}
If you find that the meshfilters are always null, you may want to double check that the meshing subsystem is running with something like this:
I was working on the headset again today and implemented the checks that you suggested (I had to figure out how to show some debug messages in the scene because I don’t know how to show console when the application is deployed on the Magic Leap), and so far it seems that OnEnabled is never executed. I first tried seeing if the meshFilters were null by putting a print statement before the return, which the line of code never ran, and a print statement after the if statement checking to see if meshFilters were null, which also never ran.
I then proceeded to check if the OnMeshesChanged method was being executed by putting a print in the first line of the method which also didn’t print anything. Checked to see if OnEnabled would run and the print statement I put in there never ran either.
I did check to see if the meshingSubsystem was on with the void Update(), and the print statement there told me that the subsystem is indeed running.
Perhaps there’s something wrong with the enabled features or permissions I have? I’ll post them here along with the updated code I have (the code is just riddled with new print statements, which are the ctf.SetText(); lines)
Your permission and XR settings look fine to me, I don’t think they’re causing an issue at the moment.
If it seems like OnEnable is never executing, that tells me there might be a NULL reference error happening somewhere, likely on meshManager.
For live debugging on the device with Unity, you can use the package called Android Logcat.
You’ll need to install it in your projects package manager and then open the Logcat window. If you have your Magic Leap device connected to your machine via USB, the Logcat package should connect to the device automatically. You can then build and run your Unity App from the Unity Editor onto your Magic Leap device and you should be able to see any logs coming from the device.
Be on the lookout for any red error text that could tell you about any errors popping up when you run your app.
Let me know how the live debugging goes!
I’d be happy to help you narrow down the issue further once we get some more debug information.
It’ll keep posting this error endlessly for as long as the application is running. The checkbox for the Spatial Mapping feature is checked within my permissions, so I’m not sure why it’s getting denied.
You may need to manually request this permission via script.
You can find out how to do that here
This should open a dialog box when you launch your app asking to accept the permission.
Alternatively, you can go into the permission settings on you Magic Leap 2 and make sure that your app has spatial mapping permissions, although please note the app will not show up here as an option if it has never requested this permission before.
My suggestion would be just to manually request the permission at runtime via script in Unity.
Let me know if you need any more help and if this corrects the issue!
Best,
Corey
So I implemented a permission script following the example in the tutorial you sent. However the physics objects I have on scene are still falling through the floor, despite the meshing system running. At first it sends a bunch of the first screenshot, which I guess is telling us that the meshing system is running and doing something (though what I’m not sure), but as the program runs longer, it transitions to the second screenshot.
I haven’t changed anything in the code since last time I worked on it.
Do you mind checking the unity Magic Leap example project. I think AR foundations handles updating the mesh collider for you. Simply apply a mesh collider to the object that is created by the system and it should update correctly. One thing I don’t remember is whether the mash needs to be marked as convex or not.