Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Question 'arsubsystems' does not exist in the namespace 'unityengine.xr' in unity reflect

Discussion in 'AR' started by MAATpe, Jun 28, 2023.

  1. MAATpe

    MAATpe

    Joined:
    Apr 12, 2023
    Posts:
    11
    Hello everyone,
    I'm currently using Unity Reflect to develop an application with the goal of using AR to overlay Revit models onto the real world. Now, I would like to place AR models based on real GPS coordinates. However, I keep encountering the error "the type or namespace name 'ARSubsystems' does not exist in the namespace 'UnityEngine.XR' (are you missing an assembly reference?)" while writing the code. Here are the versions of the AR-related packages I'm using:
    1. Unity 2020.3.42f1
    2. AR Foundation 4.1.13
    3. ARCore XR Plugin 4.1.13
    4. ARKit XR Plugin 4.1.13
    5. AR + GPS Location 4.0.0
    Below is the code in question:
    Code (CSharp):
    1. using System;
    2. using System.Collections.Generic;
    3. using SharpFlux.Dispatching;
    4. using Unity.Reflect.Viewer.Core.Actions;
    5. using UnityEngine;
    6. using UnityEngine.XR.ARFoundation;
    7. using UnityEngine.XR.ARSubsystems;
    8. using UnityEngine.UI;
    9. using UnityEngine.Reflect.Viewer.Core;
    10. using UnityEngine.Reflect.Viewer.Core.Actions;
    11.  
    12.  
    13. namespace Unity.Reflect.Viewer.UI
    14. {
    15.     public class ARSideBarController : MonoBehaviour
    16.     {
    17. #pragma warning disable CS0649
    18.         [SerializeField]
    19.         ToolButton m_BackButton;
    20.  
    21.         [SerializeField]
    22.         ToolButton m_ScaleButton;
    23.  
    24.         [SerializeField]
    25.         ToolButton m_TargetButton;
    26.  
    27.         [SerializeField]
    28.         ToolButton m_GPSButton;
    29.  
    30.         [SerializeField]
    31.         ToolButton m_HeightButton;
    32.  
    33.         [SerializeField]
    34.         GameObject m_ScaleRadial;
    35. #pragma warning restore CS0649
    36.  
    37.         bool m_ToolbarsEnabled;
    38.         List<IDisposable> m_DisposeOnDestroy = new List<IDisposable>();
    39.  
    40.         IUISelector<IARInstructionUI> m_CurrentARInstructionUIGetter;
    41.         LeftSideBarController m_LeftSideBarController;
    42.  
    43.         IUISelector<Transform> m_PlacementRootSelector;
    44.         IUISelector<Transform> m_RootSelector;
    45.         IUISelector<Transform> m_BoundingBoxRootNodeSelector;
    46.         Transform m_CursorTransform;
    47.         public GameObject scrollbarObject;
    48.         private Vector3 originalPosition;
    49.         public ARSessionOrigin arSessionOrigin;
    50.         public Transform targetObject;
    51.  
    52.  
    53.         void Awake()
    54.         {
    55.             m_DisposeOnDestroy.Add(UISelectorFactory.createSelector<bool>(UIStateContext.current, nameof(IToolBarDataProvider.toolbarsEnabled),
    56.                 data =>
    57.                 {
    58.                     m_ToolbarsEnabled = data;
    59.                 }));
    60.  
    61.             m_LeftSideBarController = GameObject.FindObjectOfType<LeftSideBarController>();
    62.  
    63.             m_DisposeOnDestroy.Add(UISelectorFactory.createSelector<bool>(ARToolStateContext.current, nameof(IARToolStatePropertiesDataProvider.scaleEnabled),
    64.                 data =>
    65.                 {
    66.                     m_ScaleButton.transform.parent.gameObject.SetActive(m_ToolbarsEnabled && data);
    67.                     m_LeftSideBarController.UpdateLayout();
    68.                 }));
    69.  
    70.             m_DisposeOnDestroy.Add(UISelectorFactory.createSelector<bool>(ARToolStateContext.current, nameof(IARToolStatePropertiesDataProvider.previousStepEnabled),
    71.                 data =>
    72.                 {
    73.                     m_BackButton.button.interactable = m_ToolbarsEnabled && data;
    74.                 }));
    75.  
    76.  
    77.             m_DisposeOnDestroy.Add(m_CurrentARInstructionUIGetter = UISelectorFactory.createSelector<IARInstructionUI>(ARContext.current, nameof(IARModeDataProvider.currentARInstructionUI)));
    78.  
    79.             m_BackButton.buttonClicked += OnBackButtonClicked;
    80.             m_ScaleButton.buttonClicked += OnScaleButtonClicked;
    81.             m_TargetButton.buttonClicked += OnTargetButtonClicked;
    82.             m_GPSButton.buttonClicked += OnGPSButtonClicked;
    83.             m_HeightButton.buttonClicked += OnHeightButtonClicked;
    84.  
    85.             m_PlacementRootSelector = UISelectorFactory.createSelector<Transform>(ARPlacementContext.current, nameof(IARPlacementDataProvider.placementRoot));
    86.             m_RootSelector = UISelectorFactory.createSelector<Transform>(PipelineContext.current, nameof(IPipelineDataProvider.rootNode));
    87.             m_BoundingBoxRootNodeSelector = UISelectorFactory.createSelector<Transform>(ARPlacementContext.current, nameof(IARPlacementDataProvider.boundingBoxRootNode));
    88.         }
    89.  
    90.         void OnDestroy()
    91.         {
    92.             m_DisposeOnDestroy.ForEach(x => x.Dispose());
    93.             m_PlacementRootSelector?.Dispose();
    94.             m_RootSelector?.Dispose();
    95.             m_BoundingBoxRootNodeSelector?.Dispose();
    96.         }
    97.  
    98.         void OnTargetButtonClicked()
    99.         {
    100.         }
    101.  
    102.         void OnScaleButtonClicked()
    103.         {
    104.             // Helpmode
    105.             if (HelpDialogController.SetHelpID(SetHelpModeIDAction.HelpModeEntryID.Scale))
    106.                 return;
    107.             Dispatcher.Dispatch(SetActiveToolBarAction.From(SetActiveToolBarAction.ToolbarType.ARScaleDial));
    108.             ARScaleRadialUIController.m_previousToolbar = SetActiveToolBarAction.ToolbarType.ARSidebar;
    109.  
    110.             var radialPosition = m_ScaleRadial.transform.position;
    111.             radialPosition.y = m_ScaleButton.transform.position.y;
    112.             m_ScaleRadial.transform.position = radialPosition;
    113.         }
    114.  
    115.         void OnBackButtonClicked()
    116.         {
    117.             // Helpmode
    118.             if (HelpDialogController.SetHelpID(SetHelpModeIDAction.HelpModeEntryID.Back))
    119.                 return;
    120.             m_CurrentARInstructionUIGetter.GetValue().Back();
    121.         }
    122.  
    123.         void OnGPSButtonClicked()
    124.         {
    125.             float latitude = 25.060495f;
    126.             float longitude = 121.6470223f;
    127.  
    128.             Vector3 targetPosition = ConvertGPSToARPosition(latitude, longitude);
    129.             targetObject.localPosition = targetPosition;
    130.  
    131.             Text arDebugTextbox = GameObject.Find("AR Debug Textbox")?.GetComponent<Text>();
    132.             if (arDebugTextbox != null)
    133.             {
    134.                 arDebugTextbox.text = "targetObject.localPosition: " + targetObject.localPosition + "\n";
    135.             }
    136.         }
    137.  
    138.         Vector3 ConvertGPSToARPosition(float lat, float lon)
    139.         {
    140.             Vector3 arPosition = arSessionOrigin.camera.transform.position;
    141.             Vector3 arForward = arSessionOrigin.camera.transform.forward;
    142.  
    143.             float x = lon;
    144.             float z = lat;
    145.             float y = arPosition.y;
    146.  
    147.             Vector3 targetPosition = new Vector3(x, y, z);
    148.             return targetPosition;
    149.         }
    150.  
    151.  
    152.  
    153.         void OnHeightButtonClicked()
    154.         {
    155.             originalPosition = m_RootSelector.GetValue().localPosition;
    156.             var scrollbar = scrollbarObject.GetComponent<Scrollbar>();
    157.             scrollbarObject.SetActive(!scrollbarObject.activeSelf);
    158.  
    159.             if (scrollbarObject.activeSelf)
    160.             {
    161.                 scrollbar.onValueChanged.AddListener(OnScrollbarValueChanged);
    162.             }
    163.             else
    164.             {
    165.                 scrollbar.onValueChanged.RemoveAllListeners();
    166.             }
    167.         }
    168.  
    169.         void OnScrollbarValueChanged(float value)
    170.         {
    171.             var rootTransform = m_RootSelector.GetValue();
    172.             var currentPosition = rootTransform.localPosition;
    173.             float mappedValue = Mathf.Lerp(-25, 25, value);
    174.  
    175.             currentPosition.y = originalPosition.y + mappedValue;
    176.             rootTransform.localPosition = currentPosition;
    177.         }
    178.     }
    179. }
    180.  
    I have added the functions OnGPSButtonClicked(), ConvertGPSToARPosition(), OnHeightButtonClicked(), and OnScrollbarValueChanged(). The purpose of OnGPSButtonClicked() and ConvertGPSToARPosition() is to move the AR model's position to the GPS coordinates when the GPS button in the AR Sidebar is clicked. However, I haven't been able to test this functionality due to the 'ARSubsystems' error. OnHeightButtonClicked() and OnScrollbarValueChanged() are responsible for moving the AR model along the y-axis, and this functionality is working without any issues.

    I have tried the following methods to solve this issue, but none of them have been successful:

    1. Deleting the Library folder to let Unity re-import.

    2. Changing the version of AR Foundation.

    3. Verifying that the reference in Unity.XR.ARFoundation.asmdef includes ARSubsystems. Here is the code in Unity.XR.ARFoundation.asmdef:
      Code (CSharp):
      1. {
      2.     "name": "Unity.XR.ARFoundation",
      3.     "references": [
      4.         "Unity.RenderPipelines.Core.Runtime",
      5.         "Unity.RenderPipelines.Lightweight.Runtime",
      6.         "Unity.RenderPipelines.Universal.Runtime",
      7.         "Unity.XR.ARSubsystems",
      8.         "Unity.XR.Management",
      9.         "UnityEngine.SpatialTracking"
      10.     ],
      11.     "includePlatforms": [],
      12.     "excludePlatforms": [],
      13.     "allowUnsafeCode": true,
      14.     "overrideReferences": false,
      15.     "precompiledReferences": [],
      16.     "autoReferenced": true,
      17.     "defineConstraints": [],
      18.     "versionDefines": [
      19.         {
      20.             "name": "com.unity.render-pipelines.lightweight",
      21.             "expression": "[5.7.2,7.0.0)",
      22.             "define": "MODULE_LWRP_ENABLED"
      23.         },
      24.         {
      25.             "name": "com.unity.render-pipelines.universal",
      26.             "expression": "7.0.0",
      27.             "define": "MODULE_URP_ENABLED"
      28.         },
      29.         {
      30.             "name": "com.unity.xr.legacyinputhelpers",
      31.             "expression": "1.0.0",
      32.             "define": "USE_LEGACY_INPUT_HELPERS"
      33.         }
      34.     ]
      35. }
      36.  
    4. Checking version compatibility.

    5. Re-importing the packages.
    I would appreciate any assistance in resolving this issue. Thank you for your help.
     
  2. andyb-unity

    andyb-unity

    Unity Technologies

    Joined:
    Feb 10, 2022
    Posts:
    789
    You have posted the assembly definition for AR Foundation, but what about the assembly definition of your code? You must also reference the AR Subsystems assembly if you use it in your code.

    Note also that Unity 2020 and AR Foundation 4.1 have reached end of life as May 2023. We encourage you to consider upgrading to Unity 2021 and AR Foundation 4.2 for continued support.
     
  3. andyb-unity

    andyb-unity

    Unity Technologies

    Joined:
    Feb 10, 2022
    Posts:
    789
    Oh I see that you are modifying the source of Unity.Reflect. Yes if you introduce a dependency on ARSubsystems then you must ARSubsystems to the assembly definition.
     
  4. MAATpe

    MAATpe

    Joined:
    Apr 12, 2023
    Posts:
    11
    Hi, I've upgraded Unity to 2021.3.15f1 and AR foundation to 4.2.8 and the problem is still there. The assembly definition already has ARSubsystems in it so I really don't know what's wrong.
     
  5. MAATpe

    MAATpe

    Joined:
    Apr 12, 2023
    Posts:
    11
    One more thing to add, I did not add any new assembly definitions in Unity Reflect. I only made changes to the code in ARSideBarController.cs and added buttons in UI Root/UI Main/Left Sidebar/Sub/AR Sidebar/Main.
     
  6. CiaranWills

    CiaranWills

    Unity Technologies

    Joined:
    Apr 24, 2020
    Posts:
    195
    You need to add the reference to the assembly definition of whichever assembly your modified code is in, which I think in this case would be in Reflect. Go up the folder hierarchy from your code until you find an assembly definition file.
     
    andyb-unity likes this.
  7. MAATpe

    MAATpe

    Joined:
    Apr 12, 2023
    Posts:
    11
    Thank you for your response. I found the ReflectViewer.asmdef file in Assets/Scripts. After adding "Unity.XR.ARSubsystems" to the references inside, the error for the line "using UnityEngine.XR.ARSubsystems;" in my ARSideBarController.cs file was resolved.

    Now, the issue is that I want to incorporate the Placing objects at runtime code from AR+GPS Location. Here is their official website: https://docs.unity-ar-gps-location.com/guide/#placing-objects-at-runtime. Below is the complete code. I added the Placing objects at runtime in the OnGPSButtonClicked() method.:

    Code (CSharp):
    1. using System;
    2. using System.Collections.Generic;
    3. using SharpFlux.Dispatching;
    4. using Unity.Reflect.Viewer.Core.Actions;
    5. using UnityEngine;
    6. using UnityEngine.UI;
    7. using UnityEngine.Reflect.Viewer.Core;
    8. using UnityEngine.Reflect.Viewer.Core.Actions;
    9. using UnityEngine.XR.ARFoundation;
    10. using UnityEngine.XR.ARSubsystems;
    11. using ARLocation;
    12.  
    13. namespace Unity.Reflect.Viewer.UI
    14. {
    15.     public class ARSideBarController : MonoBehaviour
    16.     {
    17. #pragma warning disable CS0649
    18.         [SerializeField]
    19.         ToolButton m_BackButton;
    20.  
    21.         [SerializeField]
    22.         ToolButton m_ScaleButton;
    23.  
    24.         [SerializeField]
    25.         ToolButton m_TargetButton;
    26.  
    27.         [SerializeField]
    28.         ToolButton m_GPSButton;
    29.  
    30.         [SerializeField]
    31.         ToolButton m_HeightButton;
    32.  
    33.         [SerializeField]
    34.         GameObject m_ScaleRadial;
    35. #pragma warning restore CS0649
    36.  
    37.         bool m_ToolbarsEnabled;
    38.         List<IDisposable> m_DisposeOnDestroy = new List<IDisposable>();
    39.  
    40.         IUISelector<IARInstructionUI> m_CurrentARInstructionUIGetter;
    41.         LeftSideBarController m_LeftSideBarController;
    42.  
    43.         IUISelector<Transform> m_PlacementRootSelector;
    44.         IUISelector<Transform> m_RootSelector;
    45.         IUISelector<Transform> m_BoundingBoxRootNodeSelector;
    46.         Transform m_CursorTransform;
    47.         public GameObject scrollbarObject;
    48.         private Vector3 originalPosition;
    49.         public Transform targetObject;
    50.  
    51.         void Awake()
    52.         {
    53.             m_DisposeOnDestroy.Add(UISelectorFactory.createSelector<bool>(UIStateContext.current, nameof(IToolBarDataProvider.toolbarsEnabled),
    54.                 data =>
    55.                 {
    56.                     m_ToolbarsEnabled = data;
    57.                 }));
    58.  
    59.             m_LeftSideBarController = GameObject.FindObjectOfType<LeftSideBarController>();
    60.  
    61.             m_DisposeOnDestroy.Add(UISelectorFactory.createSelector<bool>(ARToolStateContext.current, nameof(IARToolStatePropertiesDataProvider.scaleEnabled),
    62.                 data =>
    63.                 {
    64.                     m_ScaleButton.transform.parent.gameObject.SetActive(m_ToolbarsEnabled && data);
    65.                     m_LeftSideBarController.UpdateLayout();
    66.                 }));
    67.  
    68.             m_DisposeOnDestroy.Add(UISelectorFactory.createSelector<bool>(ARToolStateContext.current, nameof(IARToolStatePropertiesDataProvider.previousStepEnabled),
    69.                 data =>
    70.                 {
    71.                     m_BackButton.button.interactable = m_ToolbarsEnabled && data;
    72.                 }));
    73.  
    74.  
    75.             m_DisposeOnDestroy.Add(m_CurrentARInstructionUIGetter = UISelectorFactory.createSelector<IARInstructionUI>(ARContext.current, nameof(IARModeDataProvider.currentARInstructionUI)));
    76.  
    77.             m_BackButton.buttonClicked += OnBackButtonClicked;
    78.             m_ScaleButton.buttonClicked += OnScaleButtonClicked;
    79.             m_TargetButton.buttonClicked += OnTargetButtonClicked;
    80.             m_GPSButton.buttonClicked += OnGPSButtonClicked;
    81.             m_HeightButton.buttonClicked += OnHeightButtonClicked;
    82.  
    83.             m_PlacementRootSelector = UISelectorFactory.createSelector<Transform>(ARPlacementContext.current, nameof(IARPlacementDataProvider.placementRoot));
    84.             m_RootSelector = UISelectorFactory.createSelector<Transform>(PipelineContext.current, nameof(IPipelineDataProvider.rootNode));
    85.             m_BoundingBoxRootNodeSelector = UISelectorFactory.createSelector<Transform>(ARPlacementContext.current, nameof(IARPlacementDataProvider.boundingBoxRootNode));
    86.         }
    87.  
    88.         void OnDestroy()
    89.         {
    90.             m_DisposeOnDestroy.ForEach(x => x.Dispose());
    91.             m_PlacementRootSelector?.Dispose();
    92.             m_RootSelector?.Dispose();
    93.             m_BoundingBoxRootNodeSelector?.Dispose();
    94.         }
    95.  
    96.         void OnTargetButtonClicked()
    97.         {
    98.         }
    99.  
    100.         void OnScaleButtonClicked()
    101.         {
    102.             // Helpmode
    103.             if (HelpDialogController.SetHelpID(SetHelpModeIDAction.HelpModeEntryID.Scale))
    104.                 return;
    105.             Dispatcher.Dispatch(SetActiveToolBarAction.From(SetActiveToolBarAction.ToolbarType.ARScaleDial));
    106.             ARScaleRadialUIController.m_previousToolbar = SetActiveToolBarAction.ToolbarType.ARSidebar;
    107.  
    108.             var radialPosition = m_ScaleRadial.transform.position;
    109.             radialPosition.y = m_ScaleButton.transform.position.y;
    110.             m_ScaleRadial.transform.position = radialPosition;
    111.         }
    112.  
    113.         void OnBackButtonClicked()
    114.         {
    115.             // Helpmode
    116.             if (HelpDialogController.SetHelpID(SetHelpModeIDAction.HelpModeEntryID.Back))
    117.                 return;
    118.             m_CurrentARInstructionUIGetter.GetValue().Back();
    119.         }
    120.  
    121.         void OnGPSButtonClicked()
    122.         {
    123.             // Create a new location
    124.             var location = new Location()
    125.             {
    126.                 Latitude = 25,
    127.                 Longitude = 121,
    128.                 Altitude = 0,
    129.                 AltitudeMode = AltitudeMode.GroundRelative
    130.             };
    131.  
    132.             // Create options for placing the object
    133.             var options = new PlaceAtLocation.PlaceAtOptions()
    134.             {
    135.                 HideObjectUntilItIsPlaced = true,
    136.                 MaxNumberOfLocationUpdates = 2,
    137.                 MovementSmoothing = 0.1f,
    138.                 UseMovingAverage = false
    139.             };
    140.  
    141.             // Place the object at the location
    142.             PlaceAtLocation.AddPlaceAtComponent(objectToPlace, location, options);
    143.         }
    144.  
    145.         void OnHeightButtonClicked()
    146.         {
    147.             originalPosition = m_RootSelector.GetValue().localPosition;
    148.  
    149.             var scrollbar = scrollbarObject.GetComponent<Scrollbar>();
    150.  
    151.             scrollbarObject.SetActive(!scrollbarObject.activeSelf);
    152.  
    153.             if (scrollbarObject.activeSelf)
    154.             {
    155. scrollbar.onValueChanged.AddListener(OnScrollbarValueChanged);
    156.             }
    157.             else
    158.             {
    159.                 scrollbar.onValueChanged.RemoveAllListeners();
    160.             }
    161.         }
    162.  
    163.         void OnScrollbarValueChanged(float value)
    164.         {
    165.             var rootTransform = m_RootSelector.GetValue();
    166.             var currentPosition = rootTransform.localPosition;
    167.             float mappedValue = Mathf.Lerp(-25, 25, value);
    168.  
    169.             currentPosition.y = originalPosition.y + mappedValue;
    170.             rootTransform.localPosition = currentPosition;
    171.         }
    172.     }
    173. }
    174.  
    Currently, the line "using ARLocation;" is causing an error: Assets\Scripts\UI\Controllers\ARSideBarController.cs(11,7): error CS0246: The type or namespace name 'ARLocation' could not be found (are you missing a using directive or an assembly reference?). I have also added ARLocation to ReflectViewer.asmdef. Below is the code for ReflectViewer.asmdef:

    Code (CSharp):
    1. {
    2.     "name": "ReflectViewer",
    3.     "rootNamespace": "",
    4.     "references": [
    5.         "Unity.Reflect.Pipeline",
    6.         "Unity.InputSystem",
    7.         "Unity.Reflect",
    8.         "Unity.Reflect.Editor",
    9.         "Unity.TouchFramework",
    10.         "Unity.TextMeshPro",
    11.         "Unity.SunStudy",
    12.         "Unity.RenderPipelines.Universal.Runtime",
    13.         "Unity.RenderPipelines.Core.Runtime",
    14.         "Unity.MARS.Interfaces",
    15.         "Unity.MARS",
    16.         "Unity.MARS.Providers.ARFoundation",
    17.         "Unity.XRTools.ModuleLoader.Interfaces",
    18.         "Unity.XRTools.Utils",
    19.         "Unity.XR.Management",
    20.         "Unity.XR.Interaction.Toolkit",
    21.         "Unity.XR.OpenXR",
    22.         "Unity.MARS.Editor",
    23.         "Unity.XRTools.Utils.Editor",
    24.         "Unity.XRTools.ModuleLoader",
    25.         "Unity.XR.ARFoundation",
    26.         "Unity.XR.ARSubsystems",
    27.         "Unity.Reflect.Viewer.Core",
    28.         "Unity.Reflect.Multiplayer",
    29.         "Unity.Reflect.Viewer.MeasureTool",
    30.         "Unity.SpatialFrameworkCore",
    31.         "VivoxUnity",
    32.         "com.unity.reflect.markers.runtime",
    33.         "Unity.Properties",
    34.         "Unity.Reflect.Runtime",
    35.         "ARLocation"
    36.     ],
    37.     "includePlatforms": [],
    38.     "excludePlatforms": [],
    39.     "allowUnsafeCode": false,
    40.     "overrideReferences": true,
    41.     "precompiledReferences": [
    42.         "Reflect.dll",
    43.         "MLAPI.dll",
    44.         "Reflect.Multiplayer.dll",
    45.         "Reflect.Utils.dll"
    46.     ],
    47.     "autoReferenced": true,
    48.     "defineConstraints": [],
    49.     "versionDefines": [
    50.         {
    51.             "name": "com.unity.render-pipelines.universal",
    52.             "expression": "10.2.2",
    53.             "define": "URP_AVAILABLE"
    54.         },
    55.         {
    56.             "name": "com.unity.render-pipelines.high-definition",
    57.             "expression": "10.2.2",
    58.             "define": "HDRP_AVAILABLE"
    59.         }
    60.     ],
    61.     "noEngineReferences": false
    62. }
    63.  
    Could you please help me understand what the issue might be?
     
  8. andyb-unity

    andyb-unity

    Unity Technologies

    Joined:
    Feb 10, 2022
    Posts:
    789
    This is the same category of issue as before. If you are referencing new assemblies in your code, you must modify the corresponding assembly definitions to include references to those assemblies. This GPS location library is a third-party dependency, so any questions about it should be directed to the author of that library.