# How to programmatically reset Magic Leap 2 origin to 0,0,0 from Unity?

**URL:** https://forum.magicleap.cloud/t/how-to-programmatically-reset-magic-leap-2-origin-to-0-0-0-from-unity/4767
**Category:** Unity Development
**Tags:** development, unity, openxr
**Created:** [December 14, 2024, 7:05am UTC](https://forum.magicleap.cloud/t/how-to-programmatically-reset-magic-leap-2-origin-to-0-0-0-from-unity/4767 "2024-12-14T07:05:24Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![clonnqvist](https://avatars.discourse-cdn.com/v4/letter/c/c2a13f/32.png) [@clonnqvist](https://forum.magicleap.cloud/u/clonnqvist)
#### Post date: [December 14, 2024, 7:05am UTC](https://forum.magicleap.cloud/t/how-to-programmatically-reset-magic-leap-2-origin-to-0-0-0-from-unity/4767/1 "2024-12-14T07:05:24Z")

</div>

Environment

Unity 2022.3, ML2 SDK 2.5.0 OpenXR

Question  
How can I programmatically reset the Magic Leap 2's origin coordinates to 0,0,0? The device automatically sets its origin at startup and after tracking loss, but I need to trigger this reset through code.

What I've Tried

```auto
csharpCopyprivate XRInputSubsystem _inputSubsystem;
_inputSubsystem = XRGeneralSettings.Instance.Manager.activeLoader.GetLoadedSubsystem<XRInputSubsystem>();
_inputSubsystem.TrySetTrackingOriginMode(TrackingOriginModeFlags.Unbounded);
_inputSubsystem.TryRecenter();

```

This implementation attempts to reset the origin, but the zero point remains unchanged.

**Is there a correct way to force the ML2 to reset its origin to 0,0,0?**

I am aware of recenter XR origin at start, but it seems not to do proper zero point reset either by using this to measure the head tracking:

```auto
InputDevice hmdDevice = InputDevices.GetDeviceAtXRNode(XRNode.CenterEye);

if (hmdDevice.isValid)
{
    if (hmdDevice.TryGetFeatureValue(CommonUsages.devicePosition, out Vector3 position))
    {
        Log($"Head Position: X:{position.x:F2} Y:{position.y:F2} Z:{position.z:F2}");
    }
}

```

And Magic leap 2 Reference spaces enabled

---

<div class="post-metadata">

### Author: ![etucker](https://sea1.discourse-cdn.com/flex019/user_avatar/forum.magicleap.cloud/etucker/32/842_2.png) [@etucker](https://forum.magicleap.cloud/u/etucker)
#### Post date: [December 16, 2024, 7:19pm UTC](https://forum.magicleap.cloud/t/how-to-programmatically-reset-magic-leap-2-origin-to-0-0-0-from-unity/4767/2 "2024-12-16T19:19:33Z")

</div>

`TryRecenter()` and similar XR calls are designed for VR platforms to reset the user's "forward" direction or "floor level." On Magic Leap, the spatial coordinate system is AR-like, defined relative to the environment. Instead of altering the global origin (0,0,0), use a parent transform like `XR Origin` or `ARSessionOrigin`:

- Capture the current device position to "reset" the origin.
- Store this offset as the "new zero."

Example:

```auto
var xro = FindObjectOfType<Unity.XR.CoreUtils.XROrigin>();
xro?.MoveCameraToWorldLocation(Vector3.zero);
xro?.MatchOriginUpCameraForward(Vector3.up, Vector3.forward);

```

This approach redefines app content alignment relative to the global origin without modifying it.

Let me know if you have any questions.

---

<div class="post-metadata">

### Author: ![clonnqvist](https://avatars.discourse-cdn.com/v4/letter/c/c2a13f/32.png) [@clonnqvist](https://forum.magicleap.cloud/u/clonnqvist)
#### Post date: [December 19, 2024, 3:20am UTC](https://forum.magicleap.cloud/t/how-to-programmatically-reset-magic-leap-2-origin-to-0-0-0-from-unity/4767/3 "2024-12-19T03:20:12Z")

</div>

Thank you, this is the same code as in recenter from the startup button.

I found a way to achieve the goal

In case someone is trying to solve this still and want more power.

Search this file and open for info:

C:...\Library\PackageCache\com.unity.xr.core-utils@2.3.0\Runtime\XROrigin.cs

1. Rotation Controls:

- `RotateAroundCameraUsingOriginUp(float angleDegrees)` - Rotates around camera using origin's up vector
- `RotateAroundCameraPosition(Vector3 vector, float angleDegrees)` - Rotates around camera with custom axis

1. Origin Position & Forward:

- `MatchOriginUp(Vector3 destinationUp)` - Changes origin's up vector
- `MatchOriginUpCameraForward(Vector3 destinationUp, Vector3 destinationForward)` - Aligns camera's view direction
- `MatchOriginUpOriginForward(Vector3 destinationUp, Vector3 destinationForward)` - Aligns physical walking direction

1. Camera Position Controls:

- `MoveCameraToWorldLocation(Vector3 desiredWorldLocation)` - Teleports camera
- `CameraYOffset` property - Adjusts camera height (in Device mode)

1. Tracking Mode Controls:

- `RequestedTrackingOriginMode` property - Can be set to:
  - `TrackingOriginMode.NotSpecified`
  - `TrackingOriginMode.Device`
  - `TrackingOriginMode.Floor`

1. Read-Only Properties:

- `CurrentTrackingOriginMode` - Current tracking mode
- `OriginInCameraSpacePos` - Origin position relative to camera
- `CameraInOriginSpacePos` - Camera position relative to origin
- `CameraInOriginSpaceHeight` - Camera height relative to origin

1. Object References:

- `Camera` property - Get/set the XR camera
- `Origin` property - Get/set the origin GameObject
- `CameraFloorOffsetObject` property - Get/set floor offset object
- `TrackablesParent` property - Parent transform for trackables

---

<div class="post-metadata">

### Author: ![system](https://us1.discourse-cdn.com/flex019/uploads/magicleap1/original/1X/bd9b737a4d45ea243aa7eb177d60a773b806899a.svg) [@system](https://forum.magicleap.cloud/u/system)
#### Post date: [January 2, 2025, 3:20am UTC](https://forum.magicleap.cloud/t/how-to-programmatically-reset-magic-leap-2-origin-to-0-0-0-from-unity/4767/4 "2025-01-02T03:20:14Z")

</div>

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.
