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 AR Development

Discussion in 'AR' started by Voronoi, Jul 28, 2023.

  1. Voronoi

    Voronoi

    Joined:
    Jul 2, 2012
    Posts:
    571
    I've developed numerous AR apps and I'm about to start a new one. My question is, what is the preferred development preview that allows playing in Editor mode without having to make a build?

    I start with iOS development typically, and I found AR Foundation Remote to be indispensible. It works exactly as I would like, but I try to avoid add-ons if at all possible. At some point in development, I need to delete/remove AR Foundation to keep my builds smaller and that's a bit inconvenient.

    I don't really get Unity MARS . I don't want a preview on my computer, I want to test it with a device and point the device at my actual floor in my room for testing. I can do this with a build. AR Foundation Remote allows me to do this in the editor without having to make a build. Is AR Foundation still the best option?
     
    Brahe_ and KyryloKuzyk like this.
  2. CindyG

    CindyG

    Joined:
    Mar 29, 2019
    Posts:
    9
  3. Voronoi

    Voronoi

    Joined:
    Jul 2, 2012
    Posts:
    571
    Thanks! I got this working and it does seem to be a decent substitute for running on the device. It took me a while to find the 'Simulator' dropdown in game view to realize I can simulate various devices. Nice!

    I was able to write a script to place an object on a plane -

    Code (CSharp):
    1. using System;
    2. using System.Collections;
    3. using System.Collections.Generic;
    4. using UnityEngine;
    5. using UnityEngine.XR.ARFoundation;
    6. using UnityEngine.XR.ARSubsystems;
    7. using EnhancedTouch = UnityEngine.InputSystem.EnhancedTouch;
    8.  
    9. [RequireComponent(typeof(ARPlaneManager), typeof(ARRaycastManager))]
    10. public class ObjectCreator : MonoBehaviour
    11. {
    12.     [SerializeField] private GameObject m_prefab;
    13.  
    14.     private ARRaycastManager _arRaycastManager;
    15.     private ARPlaneManager _arPlaneManager;
    16.     private List<ARRaycastHit> _hits = new List<ARRaycastHit>();
    17.  
    18.     private void Awake()
    19.     {
    20.         _arPlaneManager = GetComponent<ARPlaneManager>();
    21.         _arRaycastManager = GetComponent<ARRaycastManager>();
    22.     }
    23.  
    24.     private void OnEnable()
    25.     {
    26.         EnhancedTouch.TouchSimulation.Enable();
    27.         EnhancedTouch.EnhancedTouchSupport.Enable();
    28.         EnhancedTouch.Touch.onFingerDown += FingerDown;
    29.     }
    30.  
    31.     private void OnDisable()
    32.     {
    33.         EnhancedTouch.Touch.onFingerDown -= FingerDown;
    34.         EnhancedTouch.TouchSimulation.Disable();
    35.         EnhancedTouch.EnhancedTouchSupport.Disable();
    36.     }
    37.  
    38.     private void FingerDown(EnhancedTouch.Finger finger)
    39.     {
    40.         if (finger.index != 0) return;
    41.  
    42.         if (_arRaycastManager.Raycast(finger.currentTouch.screenPosition, _hits, TrackableType.PlaneWithinPolygon))
    43.         {
    44.             foreach (ARRaycastHit hit in _hits)
    45.             {
    46.                 Pose pose = hit.pose;
    47.                 GameObject obj = Instantiate(m_prefab, pose.position, pose.rotation);
    48.             }
    49.         }
    50.     }
    51. }
    52.  

    However,I would like to use the XR Interaction Toolkit because it has a nice feature for translating gestures into moving and scaling. I can't seem to find how to enable TouchSimulation using a built-in Toolkit script. Does anyone have experience on how to set up TouchSimulation using XR Toolkit so that it will work with XR Simulation?

    Sorry if it's obvious, but there seems to be little information on using a combination of all these XR tools together!
     
  4. andyb-unity

    andyb-unity

    Unity Technologies

    Joined:
    Feb 10, 2022
    Posts:
    774
    Voronoi likes this.
  5. Voronoi

    Voronoi

    Joined:
    Jul 2, 2012
    Posts:
    571
    Thanks! The template on Github provided in that thread worked (sorta) for me. I can enable touch to place and move objects, but then the right-click camera navigation doesn't work. So, I can disable touch, rotate and move my camera, and then enable it again to place an object. That should be barely enough for me to start on my project.

    I'll be looking forward to a true fix for this, and of course it would be nice to simulate two-finger gestures like pinch and twirl. I am hoping that a swipe gesture will at least work with this technique.

    I've been making AR apps for at least 10 years and honestly the development workflow has pretty much always been a nightmare without a working in-editor solution to common tasks like these. AR Foundation Remote works quite well, but it's a pretty complex installation that I always have to remove at some point, thus losing my ability to troubleshoot in the editor. XRI solves on problem area, but having it work with XR Simulation will help a lot!
     
    andyb-unity likes this.
  6. LorraineBrown

    LorraineBrown

    Joined:
    Jul 28, 2023
    Posts:
    1
    Thank you for the link, you made my day. Yes, It provides a real-time connection between your Unity editor and the device, allowing you to see how your AR app behaves in a more realistic environment without needing to build and deploy the app each time. While on the hunt for an essay topic and scouring the web, I stumbled upon https://writinguniverse.com/definition-essay-topics/. This resource-rich website introduces various essay types and provides ample examples for my perusal. This exposure to diverse essay styles is proving invaluable in guiding me through my writing process.
     
    Last edited: Aug 18, 2023
    andyb-unity likes this.