# When to call \`Privacy.SetUserId\`

**URL:** <https://community.nianticspatial.com/t/when-to-call-privacy-setuserid/5174>\
**Category:** I'm Stuck\
**Created:** [February 2, 2025, 2:43am UTC](https://community.nianticspatial.com/t/when-to-call-privacy-setuserid/5174 "2025-02-02T02:43:08Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jonathan](https://avatars.discourse-cdn.com/v4/letter/j/aeb1de/32.png) [@Jonathan](https://community.nianticspatial.com/u/Jonathan)\
**Post date:** [February 2, 2025, 2:43am UTC](https://community.nianticspatial.com/t/when-to-call-privacy-setuserid/5174/1 "2025-02-02T02:43:08Z")

</div>

_Include the following details (edit as applicable):_

- **Issue category** : Lightship Maps / Semantic Segmentation / Multiplayer / Real-time Mapping-Depth / ARDK Documentation / Unity Example Package / Sample App aka ‘AR Voyage’ / ARDK Virtual Studio Tools / Developer Tools / Networking / VPS / Scanning Framework
- **Device type & OS version** : Android / iOS / Other Ex. iPhone 8+ on iOS 13
- **Host machine & OS version** : Mac / Windows / Linux / Other Ex. Mac on Big Sur x.x
- **Issue Environment** : Unity Remote / Unity Mock / On Device / Dev Portal
- **Xcode version** : 15.2
- **ARDK version** : 3
- **Unity version** : 2022.3.5

Description of the issue:

I can never call `Privacy.SetUserId` at the right time. It is either missing or too early. I am callin g it after `InitalizeLoaders` but it is still to early. Here is my code

```auto
using System.Collections;
using UnityEngine;
using UnityEngine.XR.Management;
using Niantic.Lightship.AR.Settings;
using UnityEngine.SceneManagement;

public class NewXRController : MonoBehaviour
{
    private void Start()
    {
        // Start the combined initialization/startup coroutine.
        StartCoroutine(StartXRCoroutine());
    }

    public IEnumerator StartXRCoroutine()
    {
        Debug.Log("Initializing XR...");
        yield return XRGeneralSettings.Instance.Manager.InitializeLoader();

        if (XRGeneralSettings.Instance.Manager.activeLoader == null)
        {
            Debug.LogError("Initializing XR Failed. Check Editor or Player log for details.");
        }
        else
        {
            Debug.Log("Starting XR...");
            try
            {
                string deviceName = SystemInfo.deviceName;
                if (string.IsNullOrEmpty(deviceName))
                    deviceName = "test-user";

                // See https://lightship.dev/docs/ardk/data_privacy/ for more details.
                PrivacyData.SetUserId(deviceName);
            }
            catch
            {
                Debug.Log("Error with lightship");
            }

            XRGeneralSettings.Instance.Manager.StartSubsystems();
            SceneManager.LoadScene("ARScene");

        }
    }

    /// <summary>
    /// Disables XR
    /// </summary>
    public static void DisableXR()
    {
        Debug.Log("Disabling XR");
        if (XRGeneralSettings.Instance.Manager.isInitializationComplete)
        {
            XRGeneralSettings.Instance.Manager.StopSubsystems();
            XRGeneralSettings.Instance.Manager.DeinitializeLoader();
        }
    }
}

```

It correctly initalizes XR but not lightship. If you could help that would be great

---

<div class="post-metadata">

**Author:** ![JoshM](https://avatars.discourse-cdn.com/v4/letter/j/4af34b/32.png) [@JoshM](https://community.nianticspatial.com/u/JoshM)\
**Post date:** [February 28, 2025, 6:45pm UTC](https://community.nianticspatial.com/t/when-to-call-privacy-setuserid/5174/2 "2025-02-28T18:45:33Z")

</div>

Hello! Are there any errors or logs being outputted when trying to run the script? Additionally, if possible, could you try to run your project on Unity 2022.3.37f1?

---

<div class="post-metadata">

**Author:** ![Maverick\_Niantic](https://avatars.discourse-cdn.com/v4/letter/m/8edcca/32.png) [@Maverick\_Niantic](https://community.nianticspatial.com/u/Maverick_Niantic)\
**Post date:** [March 5, 2026, 11:44pm UTC](https://community.nianticspatial.com/t/when-to-call-privacy-setuserid/5174/3 "2026-03-05T23:44:23Z")

</div>

Closed on March 5, 2026, 11:44pm UTC

Age
