Search Unity

  1. Good news ✨ We have more Unite Now videos available for you to watch on-demand! Come check them out and ask our experts any questions!
    Dismiss Notice
  2. Ever participated in one our Game Jams? Want pointers on your project? Our Evangelists will be available on Friday to give feedback. Come share your games with us!
    Dismiss Notice

ARFoundation Plane detection in Update(), FixedUpdate(), or Coroutine?

Discussion in 'Handheld AR' started by jgmakes, Jun 23, 2020.

  1. jgmakes

    jgmakes

    Joined:
    Jan 10, 2019
    Posts:
    11
    During the phase of searching for a plane / pose to set the foundation for AR content, I'm wondering if it's better to use Monobehaviour's built in Update or FixedUpdate or instead to use a Coroutine for my iOS/Android app.

    I'm using the RaycastManager to run the basic check:
    Code (CSharp):
    1. _raycastManager.Raycast(screenCenter, hits, TrackableType.Planes);
    My first assumption was always that Update ran too often and that the check happening so frequently would slow down the whole app. If that's true, FixedUpdate should theoretically cut down the number of checks, and of course a coroutine could run on whatever interval is optimal... but what would that be.

    After watching one presentation that Unity put out for "most common optimization fixes for AR," I ended up following their advice of dropping the framerate to 30, halving the resolution, and lessening the FixedUpdate interval to 0.0334s. A big part of their justification was battery usage.

    Partly I'm just curious what is best.

    Additionally, I'm curious because running on my non-flagship tester phones (iPhone 7+ and Samsung A71), I've found really suboptimal plane detection experiences. Slow. Clunky. My code is set up to search for a horizontal plane only, and when it finds one, to display a reticle / placement indicator on that plane. It is hidden again when the plane is lost.
    • The iPhone immediately shows my reticle (so it's finding a plane immediately), but often it is initially poorly calibrated, either at an incorrect visual the scale, as far off as 2x or 0.5x, before eventually settling in the correct scale (usually) 5 to 10 seconds after tracing the floor.
    • Alternately The Samsung A71 doesn't detect the plane or show a reticle for many seconds, but once it does, it's usually the correct plane. It also doesn't blink in and out–once found it's pretty stable.
    Perhaps both ARKit and ARCore are having similar detection troubles, but Android is being more hesitant about false positives compared to the trigger happy iPhone :) Anecdotally, experiences with initial detection in other iOS/Android apps, or even with Chrome's fairly new xrSession.requestHitTest() seem to be much quicker and smoother.

    I'd love any advice or pointers.

    Unity 2019.3.8
    ARFoundation 3.0.1
    ARSubsystems 3.02
    ARCore 3.0.4
    ARKit 3.0.4
     
unityunity