Unity SDK 1.4 near clip distance

You could just remove the ml camera clipping plane enforcement?

1 Like

Nope. So far I know ML hardcoded it to the SDK so it'll be always 37cm until they change it (!?)
I disabled "Enforce Near Clip Distance" on the Magic Leap camera already - what has no effect
actually on the device. Or do you have a trick to make it working?

1 Like

The clipping plane enforcement will be removed in the future version of the com.unity.xr.magicleap plugin. To disable the enforcement in the current version of the package. You will need to modify it's contents and disable the enforcement logic.

In this walkthrough we will disable the clipping plane enforcement in the MagicLeap_Examples project.

  1. Open the MagicLeap_Examples project to initialize the the packages. Then close the Unity Editor
  2. Open the project folder in your file browser. Then navigate to Library/PackageCache
  3. Copy the com.unity.xr.magicleap@7.0.0-pre.2 folder then paste it into the MagicLeap_Examples/Packages folder.
  4. The packages folder should look something like this now
  5. Using a text editor open the CameraEnforcment.cs script located in Packages/com.unity.xr.magicleap@7.0.0-pre.2/Runtime/Rendering/
  6. Comment out the contents of the EnforceCameraProperties() function. The result should look like this :
using System;

namespace UnityEngine.XR.MagicLeap.Rendering
{
    /// <summary>
    /// Static class for enforcing camera restrictions.
    /// </summary>
    internal static class CameraEnforcement
    {
        internal static void EnforceCameraProperties()
        {
            // if (Camera.main != null)
            // {
            //     // If the near clipping distance from MLGraphicsAPI is greater,
            //     // Set the main camera near clipping plane to this distance and notify the user.
            //     if (RenderingSettings.nearClipDistance - Camera.main.nearClipPlane > 0.001f)
            //     {
            //         Debug.LogWarning("The Camera\'s near clipping plane was set to a value that's beneath hardware limitations. Setting value to:" + RenderingSettings.nearClipDistance.ToString());
            //         Camera.main.nearClipPlane = RenderingSettings.nearClipDistance;
            //     }
            // }
            // else
            // {
            //     Debug.LogWarning("Main camera is null. Skipping CameraEnforcement restrictions.");
            // }
        }
    }
}
        }
    }
}
  1. Save the script with the changes.
  2. Delete the /Library folder located under MagicLeap_Examples/Library
  3. Reopen the project. The Unity packages will reinitialize
  4. Make sure the Magic Leap provider is enabled in the XR Manager Edit>Project Settings then XR Plug-in Management
  5. Finally, disable the Fix Problems On Startup and Enforce Near Clip Distance on the Magic Leap Camera Component.
1 Like

Update, you can remove the clipping plane enforcement using our latest Magic Leap Unity SDK and the com.unity.xr.magicleap 7.0.0 package. Simply add "com.unity.xr.magicleap": "7.0.0" to your dependencies in the manifest.json file located in the Packages/ folder.

1 Like

Sounds good to me. I'm using the latest Unity SDK and the package manager shows an installed 7.0.0. package. But I am not sure where to edit the manifest to add the dependencies. Do you have a sample how it looks in the android manifest? Thanks!

1 Like

com.unity.xr.magicleap: updated to 7.0.0 but near clipping is forced at 0.37.
Whether the Enforce Near Clip Distance checkbox is OFF or ON, Camera's Clipping Planes will be overwritten to 0.37.


I think this 7.0.0 update itself is pointless because the nearClip in UnityMagicLeap_RenderingTryGetParameter("NearClipDistance", out nearClip); returns 0.37.

        /// <summary>
        /// Getter/internal Setter for the near Clip distance
        /// </summary>
        public static float nearClipDistance
        {
            get
            {
                float nearClip = 0.5f;
                UnityMagicLeap_RenderingTryGetParameter("NearClipDistance", out nearClip);
                return nearClip;
            }
            internal set { UnityMagicLeap_RenderingSetParameter("NearClipDistance", value); }
        }

I can't find any description in the Developer Portal documentation on how to change the near clipping plane, so I don't know how to go about it. Please share how to do this after you have verified that the near clipping plane can be set with the current update.

Hi Leapers. Is there an implementation that is actually working and where do I change the code? No idea how to hack into the manifest.json file. Or do I have to manipulate the .apk after exporting?

1 Like

Open package.json directly under Packages/Magic Leap SDK/ and change the version of com.unity.xr.magicleap to 7.0.0 and save to reflect the change.


1 Like

Were you able to resolve this issue after updating the package to 7.0.0 ?

@kbabilinski @pepone
After updating to 7.0.0, the Near Clip is forced to be set to 0.37m whether Enforce Near Clip is turned off or on. I have not been able to resolve this issue. Please read the following post properly.

Thank you for clarifying. I misunderstood and thought your were able to solve this after updating your package. I will report this as a bug to our SDK team. In the meantime can you try running the project with both enforceNearClip and fixProblemsOnStartup to false?

Thank you for clarifying. I misunderstood and thought your were able to solve this after updating your package. I will report this as a bug to our SDK team. In the meantime can you try running the project with both enforceNearClip and fixProblemsOnStartup to false?

I tried running it as you said, but when I run it, the near clipping plane updates to 0.37.

Thank you for looking into this. To make sure the near clip is not enforced. you will need to call the following from the Awake() method:

  RenderingSettings.enforceNearClip = false;

I can't write .enforceNearClip. Is it in a different namespace than namespace UnityEngine.XR.MagicLeap,
or do I have to add using UnityEngine.somewhat on top?

When I did what you told me to do, the near clipping plane was not overwritten by 0.37 and the near clipping plane reflected the value I had set.

using UnityEngine;
using UnityEngine.XR.MagicLeap.Rendering;

public class NearClipping : MonoBehaviour
{
    private void Awake()
    {
        RenderingSettings.enforceNearClip = false;
    }
}

Just to confirm, I don't think the method you showed us is the official method. What steps did you originally expect the near clipping plane setting to take effect?

1 Like

Sorry for the confusion. For now you will have to make an additional call to disable the enforcement. However, in the future the Magic Leap Camera component will set the RenderSettings.enforceNearClip property itself. Keep an eye out on the next release notes for this change.

Cool, finally got it working! Thanks for all the help! One more question -
how do I set the magic leap's near clipping range in C#.
It seems not to be the standard Unity camera.nearClipPlane = 0.02f;

1 Like

What happens when you use Camera.NearClipPlane property? That is the property Magic Leap is using.

1 Like

You're right. I used = 0.05f to test it, what is just 5cm, so I didn't recogneize it was set :slight_smile:

1 Like

Hi,
I tried following this procedure, but I systematically end up in a totally white screen whatever I do, even if I do not change anything from the SDK. I tried reinstalling, flushing the Library folder, cleaning anything, verifying XR plugin is activated... without anymore success. No exception, no error log, nothing. The application, by the way, compile and runs properly (because of the sound I hear, and the logs I see in logcat).
Just a blank screen. Even the splash screen is not visible.

Any clue what's causing this ? It seems like the display is broken.
(Unity 2022.2.10f1, ML SDK 1.4.0, ML XR Plugin 7.0.0)

1 Like