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.

Migrating from ARKit to ARFoundation problems

Discussion in 'AR' started by JelmerV, Oct 22, 2018.

  1. JelmerV

    JelmerV

    Joined:
    Nov 29, 2012
    Posts:
    248
    Hello

    I'm migrating a project from ARKit to ARFoundation but I'm running into some problems:

    1) What are the equivelants of:

    Code (CSharp):
    1. UnityARSessionNativeInterface.ARFrameUpdatedEvent += ARFrameUpdated;
    2. UnityARSessionNativeInterface.ARSessionInterruptedEvent += ARWasInterrupted;
    2) The AR Default Plane shows up very weirdly, kind of a stingray fish
    IMG_B5BCA11EB9F9-1.jpeg

    3) I added AR Default Point Cloud to my scene: particles are nowhere to be seen?
     
    Last edited: Oct 22, 2018
  2. JelmerV

    JelmerV

    Joined:
    Nov 29, 2012
    Posts:
    248
    OK here's my final code on the ARFoundation-version of the FocusSquare.cs. It's not As fancy (i.e. no animation for the findingsquare) but should get you going! :D

    Code (CSharp):
    1. //A FocusSquare script to be used in combination with ARFoundation 1.0
    2.  
    3.  
    4. using System.Collections;
    5. using System.Collections.Generic;
    6. using UnityEngine;
    7. using UnityEngine.Experimental.XR;
    8. using UnityEngine.XR.ARFoundation;
    9.  
    10.  
    11. public class FocusSquareARF : MonoBehaviour
    12. {
    13.  
    14.     public enum FocusState { Found, Finding, Initializing };
    15.     public FocusState SquareState = FocusState.Initializing;
    16.     public ARSessionOrigin m_SessionOrigin;
    17.     Ray ray;
    18.     static List<ARRaycastHit> s_Hits = new List<ARRaycastHit>();
    19.     public GameObject focusSquareFinding; //mesh of a plane as child of the gameobject this script is on, shown when no features were found.
    20.     public GameObject focusSquareFound;  //mesh of a plane as child of the gameobject this script is on
    21.     public TrackableType whatToTrack;
    22.  
    23.  
    24.     void Update()
    25.     {
    26.         ray = Camera.main.ScreenPointToRay(new Vector3(Screen.width / 2, Screen.height / 2, 0));
    27.         if (m_SessionOrigin.Raycast(ray, s_Hits, whatToTrack))
    28.         {
    29.             //Debug.Log("hit");
    30.             Pose hitPose = s_Hits[0].pose;
    31.             transform.position = hitPose.position;
    32.             transform.rotation = hitPose.rotation;
    33.             SquareState = FocusState.Found;
    34.             focusSquareFinding.SetActive(false);
    35.             focusSquareFound.SetActive(true);
    36.  
    37.         }
    38.         else{
    39.  
    40.             SquareState = FocusState.Finding;
    41.             focusSquareFinding.SetActive(true);
    42.             focusSquareFound.SetActive(false);
    43.         }
    44.     }
    45. }

    Hierarchy setup:
    Screen Shot 2018-10-25 at 16.09.48.png


    Inspector dependencies:
    Screen Shot 2018-10-25 at 16.09.57.png
     
  3. mavisakal

    mavisakal

    Joined:
    Aug 26, 2017
    Posts:
    15
    Hi @JelmerV ,
    Have you found the equivalent of UnityARSessionNativeInterface.ARFrameUpdatedEvent += ARFrameUpdated;

    I couldn't find events documentation of ARFoundation.