Search Unity

  1. Read here for Unity's latest plans on OpenXR.
    Dismiss Notice

ARKit support for iOS via Unity-ARKit-Plugin

Discussion in 'AR' started by jimmya, Jun 5, 2017.

  1. jessevan

    jessevan

    Joined:
    Jan 3, 2017
    Posts:
    35
    @jimmya is there any chance you're team would be open to using bitbucket issues rather than the thread (I noticed there are no issues)? I find it difficult to parse conversations when they are all mixed together in one large forum thread. Perhaps the forum could be reserved for more general conversation and questions and we could use the forum to track and discuss issues?

    Just a humble suggestion.
     
  2. jimmya

    jimmya

    Unity Technologies

    Joined:
    Nov 15, 2016
    Posts:
    793
    Indeed - I just enabled "issues" recently for this purpose, but there does not appear to be any activity there :)
     
    jessevan likes this.
  3. jessevan

    jessevan

    Joined:
    Jan 3, 2017
    Posts:
    35
    Thanks @jimmya! From now on I'll post issues there.
     
  4. Yogesh_MV

    Yogesh_MV

    Joined:
    Dec 22, 2016
    Posts:
    5
    i configured all the settings i need but still getting the same error.
     

    Attached Files:

  5. Griffo

    Griffo

    Joined:
    Jul 5, 2011
    Posts:
    677
    Hi, when I use the below UnityARUserAnchorComponent script on a GO then destroy it the app crashes with this Xcode message .. Any Idea why? .. Thanks.

    Screen Shot 2018-01-17 at 10.31.43.png

    Code (CSharp):
    1. using System;
    2. using System.Collections;
    3. using System.Collections.Generic;
    4. using UnityEngine;
    5. using UnityEngine.XR.iOS;
    6.  
    7. namespace UnityEngine.XR.iOS
    8. {
    9. public class UnityARUserAnchorComponent : MonoBehaviour {
    10.  
    11.     private string m_AnchorId;
    12.  
    13.     public string AnchorId  { get { return m_AnchorId; } }
    14.  
    15.     void Awake()
    16.     {
    17.         UnityARSessionNativeInterface.ARUserAnchorUpdatedEvent += GameObjectAnchorUpdated;
    18.         UnityARSessionNativeInterface.ARUserAnchorRemovedEvent += AnchorRemoved;
    19.         this.m_AnchorId = UnityARSessionNativeInterface.GetARSessionNativeInterface ().AddUserAnchorFromGameObject(this.gameObject).identifierStr;
    20.     }
    21.     void Start () {
    22.  
    23.     }
    24.  
    25.     public void AnchorRemoved(ARUserAnchor anchor)
    26.     {
    27.         if (anchor.identifier.Equals(m_AnchorId))
    28.         {
    29.             Destroy(this.gameObject);
    30.         }
    31.     }
    32.  
    33.     void OnDestroy() {
    34.         UnityARSessionNativeInterface.ARUserAnchorUpdatedEvent -= GameObjectAnchorUpdated;
    35.         UnityARSessionNativeInterface.ARUserAnchorRemovedEvent -= AnchorRemoved;
    36.         UnityARSessionNativeInterface.GetARSessionNativeInterface ().RemoveUserAnchor(this.m_AnchorId);
    37.     }
    38.  
    39.     private void GameObjectAnchorUpdated(ARUserAnchor anchor)
    40.     {
    41.      
    42.     }
    43. }
    44. }
     
    el_noobo likes this.
  6. SkaZonic

    SkaZonic

    Joined:
    Jun 20, 2017
    Posts:
    23
    Screen Shot 2018-01-17 at 13.30.52.png

    Hey guys,

    So I recently updated the ARKit package and I am getting these errors. Anyone know whats up with this? Thanks in advance!
     
  7. el_noobo

    el_noobo

    Joined:
    Jan 10, 2018
    Posts:
    4
    I did a thing, I took the space shooter assets from the unity official tutorial and sort of...bastardized it, in an experiment/uni assignment.

    If anyone wants to take a look, here's the link to the video: https://instagram.com/p/BeD1bCLhfs3/
    Can't embed media from instagram on the forum (), so here's a still:



    So the user can place a playspace of 2 meters in width, 2 meters in height, and 5 meters in depth. The enemies spawn from one end to the other end. The boss, which you can see in the still, travels along a randomly generated path to add some spice.

    The idea was inspired by the Vive, I was trying to see if you could sort of replicate the "Room Scale" functionality.
    But you can go way beyond it.
     
    Griffo likes this.
  8. el_noobo

    el_noobo

    Joined:
    Jan 10, 2018
    Posts:
    4

    Is it possible to make the GO, a prefab and then add it to unity AR user anchor example by replacing the prefab that should be visible in the inspector, rather than making it active in the hierarchy. It may be that you can only place the user anchors, after the session has been started, rather than before in the scene view.
     
  9. cliu10

    cliu10

    Joined:
    May 11, 2017
    Posts:
    3
    I imported the plugin, open the ARKitscene and then hit play. The error message "Screen position out of view frustum (screen pos 0.000000, 0.000000, 30.000000) (Camera rect 0 0 480 320)" just keep popping up. I can't really figure out what's going on. Can someone provide some direction, please? Thank you!




    If I turn off ARCameraManager script, then the error message stopped. But I am sure it shouldn't be the problem since its pretty much plug and play scene, everything should work just fine...
     

    Attached Files:

    Last edited: Jan 18, 2018
    SkaZonic likes this.
  10. titisriz

    titisriz

    Joined:
    Oct 8, 2015
    Posts:
    4
    hi, i tried to run my app in outdoor, and i notice that my model is shaking a little when i walk to the model or moving the device. The surface is mainly grass and i run the app while standing. Is this normal behaviour since the surface that i tracked is far away?
     
  11. Griffo

    Griffo

    Joined:
    Jul 5, 2011
    Posts:
    677
    Hi, thanks for the reply, the GO is being put into the scene as a prefab after the session has started.
     
  12. SkaZonic

    SkaZonic

    Joined:
    Jun 20, 2017
    Posts:
    23

    I am also having the same problem :(
    Still couldn't figure it out!
     
  13. dienat

    dienat

    Joined:
    May 27, 2016
    Posts:
    399
    Hi,

    Anyone knows how to integrate arkit with artoolkit? artoolkit can show a 3d object in the recognized image marker but just when you look at the marker and i want to have permanent 3d objects like in arkit
     
  14. el_noobo

    el_noobo

    Joined:
    Jan 10, 2018
    Posts:
    4
    Is that through the example user anchor adder given in the plugin, or is that a direct prefab in hierarchy?
     
  15. Griffo

    Griffo

    Joined:
    Jul 5, 2011
    Posts:
    677
    OK what I've tried is this, on the 'debugPlanePrefab' I've added the 2 scripts, the 'UnityARUserAnchorComponent' and 'UnityARUserAnchorExampleEdited.cs' a edited version of 'UnityARUserAnchorExample' I've just taken out the update and added a wait function that is called from Awake.

    when run it generates planes in the scene and after the yield time they disappear but the App will freeze with the below error ?

    Code (CSharp):
    1. using System;
    2. using System.Collections;
    3. using System.Collections.Generic;
    4. using UnityEngine;
    5. using UnityEngine.XR.iOS;
    6.  
    7. namespace UnityEngine.XR.iOS
    8. {
    9.     public class UnityARUserAnchorComponent : MonoBehaviour {
    10.    
    11.         private string m_AnchorId;
    12.    
    13.         public string AnchorId  { get { return m_AnchorId; } }
    14.    
    15.         void Awake()
    16.         {
    17.             UnityARSessionNativeInterface.ARUserAnchorUpdatedEvent += GameObjectAnchorUpdated;
    18.             UnityARSessionNativeInterface.ARUserAnchorRemovedEvent += AnchorRemoved;
    19.             this.m_AnchorId = UnityARSessionNativeInterface.GetARSessionNativeInterface ().AddUserAnchorFromGameObject(this.gameObject).identifierStr;
    20.         }
    21.         void Start () {
    22.    
    23.         }
    24.    
    25.         public void AnchorRemoved(ARUserAnchor anchor)
    26.         {
    27.             if (anchor.identifier.Equals(m_AnchorId))
    28.             {
    29.                 Destroy(this.gameObject);
    30.             }
    31.         }
    32.    
    33.         void OnDestroy() {
    34.             UnityARSessionNativeInterface.ARUserAnchorUpdatedEvent -= GameObjectAnchorUpdated;
    35.             UnityARSessionNativeInterface.ARUserAnchorRemovedEvent -= AnchorRemoved;
    36.             UnityARSessionNativeInterface.GetARSessionNativeInterface ().RemoveUserAnchor(this.m_AnchorId);
    37.         }
    38.    
    39.         private void GameObjectAnchorUpdated(ARUserAnchor anchor)
    40.         {
    41.            
    42.         }
    43.     }
    44. }
    and ..

    Code (CSharp):
    1. using System;
    2. using System.Collections;
    3. using System.Collections.Generic;
    4. using System.Runtime.InteropServices;
    5. using UnityEngine;
    6. using UnityEngine.XR.iOS;
    7.  
    8. public class UnityARUserAnchorExampleEdited : MonoBehaviour {
    9.  
    10.     private HashSet<string> m_Clones;
    11.     private float m_TimeUntilRemove = 5.0f;
    12.  
    13.     void  Awake() {
    14.         UnityARSessionNativeInterface.ARUserAnchorAddedEvent += ExampleAddAnchor;
    15.         UnityARSessionNativeInterface.ARUserAnchorRemovedEvent += AnchorRemoved;
    16.         m_Clones = new HashSet<string>();
    17.  
    18.         StartCoroutine(wait());
    19.     }
    20.    
    21.     public void ExampleAddAnchor(ARUserAnchor anchor)
    22.     {
    23.         if (m_Clones.Contains(anchor.identifier))
    24.         {
    25.             Console.WriteLine("Our Plane anchor was added!");
    26.         }
    27.     }
    28.  
    29.     public void AnchorRemoved(ARUserAnchor anchor)
    30.     {
    31.         if (m_Clones.Contains(anchor.identifier))
    32.         {
    33.             m_Clones.Remove(anchor.identifier);
    34.             Console.WriteLine("PlaneAnchorRemovedExample : " + anchor.identifier);
    35.         }
    36.     }
    37.        
    38.     private IEnumerator wait () {
    39.  
    40.         yield return new WaitForSeconds(2);
    41.  
    42.         UnityARUserAnchorComponent component = this.gameObject.GetComponent<UnityARUserAnchorComponent>();
    43.         m_Clones.Add(component.AnchorId);
    44.  
    45.         yield return new WaitForSeconds(4);
    46.  
    47.         foreach (string id in m_Clones)
    48.         {
    49.             Console.WriteLine("Removing Plane anchor with id: " + id);
    50.             UnityARSessionNativeInterface.GetARSessionNativeInterface().RemoveUserAnchor(id);
    51.             break;
    52.         }
    53.     }
    54. }
    Screen Shot 2018-01-18 at 16.24.16.png

    Screen Shot 2018-01-18 at 16.24.46.png
     
  16. jimmya

    jimmya

    Unity Technologies

    Joined:
    Nov 15, 2016
    Posts:
    793
    This is fixed with latest plugin on BitBucket, but it is harmless - the main problem is that you're trying to run this scene in the Editor - this will not work unless you have connected to ARKit Remote.
     
    cliu10 likes this.
  17. erikwp

    erikwp

    Joined:
    Jan 16, 2018
    Posts:
    13
    I am getting the wrong camera image appearing in my scene when using ARKit Remote. It is using my desktop webcam instead of my ipad camera. Is there a way to switch this setting? I am already selecting the correct device in the console window. Thanks
     
  18. el_noobo

    el_noobo

    Joined:
    Jan 10, 2018
    Posts:
    4

    If you attach the two scripts to the single prefab, wouldn't keeping a list/hash-set be pointless because m_clones would only ever contain a single m clones.

    I think, the error is because of
    1. UnityARSessionNativeInterface.GetARSessionNativeInterface ().RemoveUserAnchor(this.m_AnchorId). Being run twice to remove the same anchor id from the session interface.
    One time at the end of the for each loop, and the second time at the end of the on Destroy method.

    Could you try commenting out the
    Code (csharp):
    1.  
    2.  
    3. [LIST=1]
    4. [*]        void OnDestroy() {
    5. [*]            UnityARSessionNativeInterface.ARUserAnchorUpdatedEvent -= GameObjectAnchorUpdated;
    6. [*]            UnityARSessionNativeInterface.ARUserAnchorRemovedEvent -= AnchorRemoved;
    7. [*]            //UnityARSessionNativeInterface.GetARSessionNativeInterface ().RemoveUserAnchor(this.m_AnchorId);
    8. [*]        }
    9. [/LIST]
    10.  
    In the first script? The last line in the on destroy
     
  19. Griffo

    Griffo

    Joined:
    Jul 5, 2011
    Posts:
    677
    Tanks for the input, but sorry to say it still crashes .. :(

    EDIT .. If I just have "UnityARUserAnchorComponent.cs' on the plane prefab and destroy it the it still crashes ..
     
    Last edited: Jan 19, 2018
  20. jimmya

    jimmya

    Unity Technologies

    Joined:
    Nov 15, 2016
    Posts:
    793
    I don't see how that is even possible unless you have added a WebCamTexture somewhere in your project.
     
  21. bsebag

    bsebag

    Joined:
    Apr 5, 2017
    Posts:
    10
    The last version of the arkit plugin released on Jan 18th 2018, introduced 02 new issues:
    1) An error message related to the camera: "screen position out of view frustum"
    2) The access via mobile for the game view becomes mandatory. Why does the game view no longer works and demands a mandatory connection with the device ?
     
  22. cliu10

    cliu10

    Joined:
    May 11, 2017
    Posts:
    3
    thank you, Jimmya. I got it running now.
     
  23. Kelborn

    Kelborn

    Joined:
    Feb 10, 2016
    Posts:
    9
    @jimmya , do you have shader for plane that supports shadows, occlusion and tiling texture all in one? Or any ideas how to implement it with standard arkit shaders?
     
  24. AquaGhost

    AquaGhost

    Joined:
    Jan 27, 2013
    Posts:
    77
    @jimmya is there a simple way to prevent it from demanding the AR Remote? We have some scenes where we wrote them to have easy testing in editor mode for devs who arent on ios. (previously, you could just disable the Remote object in the scene)
     
    Last edited: Jan 22, 2018
  25. jimmya

    jimmya

    Unity Technologies

    Joined:
    Nov 15, 2016
    Posts:
    793
    I added that to make it simpler for people to connect to Remote. I guess I should put it on a settings flag. For your purposes, you could try commenting out the code in the #if !UNITY_EDITOR block in UnityARSessionNativeInterface.cs:

    #else
    CreateRemoteWorldTrackingConnection(config, runOptions);
    #endif
     
  26. jimmya

    jimmya

    Unity Technologies

    Joined:
    Nov 15, 2016
    Posts:
    793
    You should be able to add the different materials to your plane meshrenderer to get the result you need.
     
  27. wpeay

    wpeay

    Joined:
    Aug 10, 2017
    Posts:
    8
    If I update my current project to the lastest version of Arkit plugin, what will happen to my assets? Will all my scenes be reset?

    Since, this is something I've actually never done before. Would really stink if all of my placements got reset
     
    Last edited: Jan 22, 2018
  28. jimmya

    jimmya

    Unity Technologies

    Joined:
    Nov 15, 2016
    Posts:
    793
    If you notice, the ARKit plugin is a folder called UnityARKitPlugin - only the files in that folder and its subfolders are going to change - it should not affect the rest of the files that you may have created.
     
  29. wpeay

    wpeay

    Joined:
    Aug 10, 2017
    Posts:
    8
    I'm also getting the Screen frustum error. I have edited out the:

    #else
    CreateRemoteWorldTrackingConnection(config, runOptions);
    #endif

    Still getting errors
     
  30. jimmya

    jimmya

    Unity Technologies

    Joined:
    Nov 15, 2016
    Posts:
    793
    As mentioned above, the screen frustum errors are benign (does not stop anything from working), and due to a all zeroes projection matrix. There is a fix for it in bitbucket at this commit. Not yet on Asset Store.
     
  31. HisDarkHumour

    HisDarkHumour

    Joined:
    Aug 23, 2017
    Posts:
    3
    hello, I'm not sure if this has been asked here already, I've been reading through all of it but not come across the answer just yet.
    so here goes....
    I'm new to all this, and I've been trying to look for a way to deactivate(disable?) the UnityARHitTestExample component after it has been succesfully used to place a group of objects (childed to the hit test cube) . I've tried a few solutions, including attempting to make a button that would turn the script components off, (that has not gone well) also I did get them to disable from within the UnityARHitTestExample script itself, but am not sure how to do it so that it succesfully places the objects first (it just seemed to deactivate without any choice where they went).

    Any help would be much appreciated. And thanks to whoever made this, its bloody brilliant.
     
  32. Kelborn

    Kelborn

    Joined:
    Feb 10, 2016
    Posts:
    9
    Ah, obviously. Thx)
     
    Last edited: Jan 23, 2018
  33. wpeay

    wpeay

    Joined:
    Aug 10, 2017
    Posts:
    8
    Okay, I'm okay with waiting for the asset store update.

    Another issue I have, deals with two Null Ref errors. I'm only getting on one of my scenes out of 4. I have my project set up to have a load screen, and I think since I added that in, I've been getting this issue
     

    Attached Files:

  34. LingDar

    LingDar

    Joined:
    Dec 28, 2016
    Posts:
    2
    I just started to play with the Face tracking with the iPhoneX and I love the Remote.
    I am struggling to disabled the background video so I can create an animoji type scene.
    Any suggestions on how to do that?

    Thanks for this awesome asset.
     
  35. Pilot-365

    Pilot-365

    Joined:
    Aug 9, 2017
    Posts:
    11
  36. jimmya

    jimmya

    Unity Technologies

    Joined:
    Nov 15, 2016
    Posts:
    793
    Remove the UnityARVideo component from the camera.
     
  37. mark5522

    mark5522

    Joined:
    Oct 31, 2017
    Posts:
    1
    Hello, I'd like to consult with you. I have installed the arkit plug-in. And a model is placed in the scene of unit. The arkit was directly activated without a test, which makes the model was particularly unstable and jitter. How can I deal with it? And where can I see your update info.?
     
  38. Gametyme

    Gametyme

    Joined:
    May 7, 2014
    Posts:
    581
    Is there a way to get a camera permission state callback with ar kit?
     
    Last edited: Jan 24, 2018
  39. mm_sto

    mm_sto

    Joined:
    Aug 28, 2017
    Posts:
    16
  40. sam598

    sam598

    Joined:
    Sep 21, 2014
    Posts:
    59
    iOS Developer Beta is up! Fingers crossed the Apple people gave the Unity people a preview of the preview.
     
    Last edited: Jan 24, 2018
  41. adeutsch

    adeutsch

    Joined:
    Jan 24, 2018
    Posts:
    1
    download button's not working over here...did you have any luck?
     
  42. sam598

    sam598

    Joined:
    Sep 21, 2014
    Posts:
    59
    Under General/Software Update it greyed out until I connected to WiFi.

    Horizontal plane detection seems to be faster... a lot faster...
     
    adeutsch likes this.
  43. macdude2

    macdude2

    Joined:
    Sep 22, 2010
    Posts:
    685
    @jimmya Just saw on macrumors that 11.3 is supposed to include vertical wall arkit information. Any idea when the unity plugin will support this as well?

    "iOS 11.3 will feature ARKit 1.5. In addition to horizontal surfaces like tables and chairs, Apple's updated augmented reality platform will now be able to recognize and place virtual objects on vertical surfaces like walls and doors, and more accurately map irregularly shaped surfaces like circular tables.

    ARKit 1.5 can find and recognize the position of 2D images such as signs, posters, and artwork, and integrate these real-world images into augmented reality experiences, such as bringing a movie poster to life. In addition, the view of the "real world" will now be in 1080p HD, up from 720p currently."
     
  44. Jason-RT-Bond

    Jason-RT-Bond

    Joined:
    Mar 26, 2012
    Posts:
    66
    The latest store version has a compile error on Windows:

    The problem is in UnityARBuildPostprocessor.cs:
    Code (CSharp):
    1. using UnityEditor.iOS.Xcode;
     
  45. sam598

    sam598

    Joined:
    Sep 21, 2014
    Posts:
    59
    If anyone is impatient like me….

    In “ARSessionNative.mm” change:

    Code (ObjectiveC):
    1. static inline ARPlaneDetection GetARPlaneDetectionFromUnityARPlaneDetection(UnityARPlaneDetection planeDetection)
    2. {
    3.     ARPlaneDetection ret = ARPlaneDetectionNone;
    4.     if ((planeDetection & UnityARPlaneDetectionNone) != 0)
    5.         ret |= ARPlaneDetectionNone;
    6.     if ((planeDetection & UnityARPlaneDetectionHorizontal) != 0)
    7.         ret |= ARPlaneDetectionHorizontal;
    8.     return ret;
    9. }
    To:

    Code (ObjectiveC):
    1. static inline ARPlaneDetection GetARPlaneDetectionFromUnityARPlaneDetection(UnityARPlaneDetection planeDetection)
    2. {
    3.     ARPlaneDetection ret = ARPlaneDetectionNone;
    4.     if ((planeDetection & UnityARPlaneDetectionNone) != 0)
    5.         ret |= ARPlaneDetectionNone;
    6.     if ((planeDetection & UnityARPlaneDetectionHorizontal) != 0)
    7.         ret |= ARPlaneDetectionHorizontal;
    8.     if ((planeDetection & UnityARPlaneDetectionVertical) != 0)
    9.         ret |= ARPlaneDetectionVertical;
    10.     return ret;
    11. }
    In “ARPlaneAnchorAlignment.cs” change:

    Code (CSharp):
    1. public enum ARPlaneAnchorAlignment : long
    2. {
    3. /** A plane that is horizontal with respect to gravity. */
    4. ARPlaneAnchorAlignmentHorizontal
    5. }
    To:

    Code (CSharp):
    1. public enum ARPlaneAnchorAlignment : long
    2. {
    3. /** A plane that is horizontal with respect to gravity. */
    4. ARPlaneAnchorAlignmentHorizontal,
    5. ARPlaneAnchorAlignmentVertical
    6. }
    In “UnityARSessionNative.cs” change:

    Code (CSharp):
    1. public enum UnityARPlaneDetection
    2. {
    3.     None = 0,
    4.     Horizontal = (1 << 0)
    5. }
    To:

    Code (CSharp):
    1. public enum UnityARPlaneDetection
    2. {
    3.     None = 0,
    4.     Horizontal = (1 << 0),
    5. Vertical = (1 << 1)
    6. }

    Finally change the “Plane Detection” variables of the “ARCameraManager” in your scene to “Vertical”.
     
    jason_sone, adeutsch and parth4054 like this.
  46. macdude2

    macdude2

    Joined:
    Sep 22, 2010
    Posts:
    685
    Wait, damn, does this work?!! How well does vertical plane detection work for you?
     
    cstenson likes this.
  47. sam598

    sam598

    Joined:
    Sep 21, 2014
    Posts:
    59
    It does! I would say detection time/quality for vertical planes is about what horizontal planes were for the original beta of ARKit. I'm curious to see what the irregular tracked planes look like.


    (I had a shader on the camera which is why it's so dark)
     
    cstenson, parth4054 and Fl0oW like this.
  48. macdude2

    macdude2

    Joined:
    Sep 22, 2010
    Posts:
    685
    That's awesome! I ended up trying it out myself, and was pretty hyped when it worked. Though the vertical surfaces seem to still need to be pretty noisy for detection to work correctly. Also, unless you manually switch detection types it looks like it can't do vertical and horizontal planes simultaneously... Maybe Arkit 1.6? Though it looks like both plane types can exist at the same time, just takes some user input...
     
  49. JelmerV

    JelmerV

    Joined:
    Nov 29, 2012
    Posts:
    219
    It's really cool that Apple made this, but it also makes it pretty clear that we need a depth camera like Hololens to be able to track all surfaces in the room. Because as mentioned, ARKit just can't detect a wall that has no feature points (=most walls)
     
  50. eco_bach

    eco_bach

    Joined:
    Jul 8, 2013
    Posts:
    1,423
    So is ARkit 1.5 available BEFORE the 11.3 iOS rollout this spring?
    Confused by the above posts and demos...were they done with iOS 11.25?
     
    Last edited: Jan 25, 2018
unityunity