# Recenter the view during runtime in Unity

**URL:** <https://forum.magicleap.cloud/t/recenter-the-view-during-runtime-in-unity/2854>\
**Category:** Unity Development\
**Tags:** development, unity, app-sim\
**Created:** [November 8, 2023, 8:57pm UTC](https://forum.magicleap.cloud/t/recenter-the-view-during-runtime-in-unity/2854 "2023-11-08T20:57:42Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ethan](https://avatars.discourse-cdn.com/v4/letter/e/8dc957/32.png) [@Ethan](https://forum.magicleap.cloud/u/Ethan)\
**Post date:** [November 8, 2023, 8:57pm UTC](https://forum.magicleap.cloud/t/recenter-the-view-during-runtime-in-unity/2854/1 "2023-11-08T20:57:42Z")

</div>

Give us as much detail as possible regarding the issue you're experiencing.

**Unity Editor version** : 2022.2.0f1  
**ML2 OS version** :  
**MLSDK version** : 1.2.0-dev2  
**Host OS** : (/MacOS)

Hi,  
I am building a Unity app but I am having constant view issue when testing it using App-sim and after installation. This happens quite often: after removing my headset and putting it back, the camera in Unity (input is from centereyerotation) is set to a rotation value even when I am looking straight. The only way I know so far to recenter the view is using the home button on the controller. But this won't work when running an App. I am wondering if there is any way to recenter the headset to the direction I am facing during runtime in Unity?

Thanks in advance!

---

<div class="post-metadata">

**Author:** ![aheaney](https://avatars.discourse-cdn.com/v4/letter/a/f08c70/32.png) [@aheaney](https://forum.magicleap.cloud/u/aheaney)\
**Post date:** [November 9, 2023, 6:29am UTC](https://forum.magicleap.cloud/t/recenter-the-view-during-runtime-in-unity/2854/2 "2023-11-09T06:29:01Z")

</div>

Hi Ethan,

Welcome to the forum! If you're using the XR Rig prefab from the MagicLeap Unity sdk- there is a MagicLeapCamera component on the Main Camera game object.

If you enable the "Recenter XR Origin At Start" property, then the XR origin will be set to the scene origin in Unity world space when the app launches-

 ![image](https://us1.discourse-cdn.com/flex019/uploads/magicleap1/original/2X/1/1f69c6e95dc9fa8de536010809c9e2994faa277b.png)

Please let us know if that doesn't provide the behavior that you are trying to achieve.

Best,  
Adam

---

<div class="post-metadata">

**Author:** ![evolvingtech](https://avatars.discourse-cdn.com/v4/letter/e/eada6e/32.png) [@evolvingtech](https://forum.magicleap.cloud/u/evolvingtech)\
**Post date:** [January 29, 2024, 4:42am UTC](https://forum.magicleap.cloud/t/recenter-the-view-during-runtime-in-unity/2854/3 "2024-01-29T04:42:11Z")

</div>

Thank you for pointing out about enabling Recenter XR Origin At Start. I note that Magic Leap Camera script is marked as Deprecated. Going forward, how will this be handled with Open XR?

---

<div class="post-metadata">

**Author:** ![kbabilinski](https://sea1.discourse-cdn.com/flex019/user_avatar/forum.magicleap.cloud/kbabilinski/32/19_2.png) [@kbabilinski](https://forum.magicleap.cloud/u/kbabilinski)\
**Post date:** [January 29, 2024, 4:26pm UTC](https://forum.magicleap.cloud/t/recenter-the-view-during-runtime-in-unity/2854/4 "2024-01-29T16:26:03Z")

</div>

In OpenXR we use the integrated XR Origin Features:

> **[Tracking Origin Example | MagicLeap Developer Documentation](https://developer-docs.magicleap.cloud/docs/guides/unity-openxr/reference-space/tracking-origin-example/)**
>
> The Magic Leap Reference Space OpenXR Feature allows developers to change the Tracking Origin Mode. This can be done directly on the XR Origin Component or, for greater flexibility, programmatically.

Since it's using the underlying Unity Subsystem, you may also be able to call  
[`XRInputSubsystem.TryRecenter`](https://docs.unity3d.com/ScriptReference/XR.XRInputSubsystem.TryRecenter.html)

---

<div class="post-metadata">

**Author:** ![evolvingtech](https://avatars.discourse-cdn.com/v4/letter/e/eada6e/32.png) [@evolvingtech](https://forum.magicleap.cloud/u/evolvingtech)\
**Post date:** [January 29, 2024, 11:13pm UTC](https://forum.magicleap.cloud/t/recenter-the-view-during-runtime-in-unity/2854/5 "2024-01-29T23:13:26Z")

</div>

Thank you for the quick response. I'll take a look at this.

---

<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:** [February 13, 2024, 11:13pm UTC](https://forum.magicleap.cloud/t/recenter-the-view-during-runtime-in-unity/2854/6 "2024-02-13T23:13:49Z")

</div>

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