Search Unity

[bug] AR Object Importer

Discussion in 'AR/VR (XR) Discussion' started by crocvr, Feb 3, 2020.

  1. crocvr

    crocvr

    Joined:
    Oct 7, 2015
    Posts:
    44
    Hi!
    We tried to use AR object tracking with ARkit and found a little bug. When ARkit scan an object and produce xml arobject file it use dots for floats. If I tried to import it by ARObjectImporter from ARkit plugin i received an error.

    Code (CSharp):
    1. FormatException: Input string was not in a correct format.
    2. System.Number.ParseSingle (System.String value, System.Globalization.NumberStyles options, System.Globalization.NumberFormatInfo numfmt) (at <437ba245d8404784b9fbab9b439ac908>:0)
    3. System.Single.Parse (System.String s, System.Globalization.NumberStyles style, System.Globalization.NumberFormatInfo info) (at <437ba245d8404784b9fbab9b439ac908>:0)
    4. System.Single.Parse (System.String s) (at <437ba245d8404784b9fbab9b439ac908>:0)
    5. UnityEditor.XR.ARKit.ARObjectInfo.GetWithDefault (System.Collections.Generic.Dictionary`2[TKey,TValue] dict, System.String key, UnityEngine.Quaternion defaultValue) (at Library/PackageCache/com.unity.xr.arkit@3.1.0-preview.4/Editor/ObjectTracking/ARObjectInfo.cs:118)
    6. UnityEditor.XR.ARKit.ARObjectInfo..ctor (System.Xml.XmlDocument plist) (at Library/PackageCache/com.unity.xr.arkit@3.1.0-preview.4/Editor/ObjectTracking/ARObjectInfo.cs:39)
    7. UnityEditor.XR.ARKit.ARObjectImporter.ReadInfo (System.String path) (at Library/PackageCache/com.unity.xr.arkit@3.1.0-preview.4/Editor/ObjectTracking/ARObjectImporter.cs:96)
    8. UnityEditor.XR.ARKit.ARObjectImporter.ReadARObject (System.String path) (at Library/PackageCache/com.unity.xr.arkit@3.1.0-preview.4/Editor/ObjectTracking/ARObjectImporter.cs:46)
    9. UnityEditor.XR.ARKit.ARKitReferenceObjectEntryEditor.OnInspectorGUI () (at Library/PackageCache/com.unity.xr.arkit@3.1.0-preview.4/Editor/ObjectTracking/ARKitReferenceObjectEntryEditor.cs:51)
    10. UnityEditor.UIElements.InspectorElement+<>c__DisplayClass55_0.<CreateIMGUIInspectorFromEditor>b__0 () (at <6f28216fea9f453abf2e05b770ed3ee4>:0)
    11. UnityEngine.GUIUtility:ProcessEvent(Int32, IntPtr)
    12.  
    I inspected this problem and I found out that the problem have been appeared beacuse of my default CultureInfo (It is ru-RU). So I wrote a little script to fix it but it is just workaround.

    Code (CSharp):
    1. using System.Globalization;
    2. using System.IO;
    3. using UnityEngine;
    4. #if UNITY_EDITOR
    5. using UnityEditor;
    6. #endif
    7.  
    8. public class FixARObjectImporter : MonoBehaviour
    9. {
    10. #if UNITY_EDITOR
    11.     [InitializeOnLoadMethod]
    12.     public static void FixObjectImporter()
    13.     {
    14.         var file = Directory.GetFiles(Application.dataPath, "*.arobject", SearchOption.AllDirectories);
    15.         if (file.Length <= 0) return;
    16.         CultureInfo.CurrentCulture = new CultureInfo("en-US");
    17.         Debug.LogWarning("WARNING: <color=yellow>CultureInfo was modified to en-US.</color>");
    18.     }
    19. #endif
    20. }