Search Unity

  1. Unity 2020.1 has been released.
    Dismiss Notice
  2. 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

Foundation AR, ARSessionOrigin doesn't reconize the Raycast method?

Discussion in 'AR' started by miranoren, May 17, 2019.

  1. miranoren

    miranoren

    Joined:
    Dec 4, 2016
    Posts:
    1
    Hi,

    So I just started production with AR Foundation, but I get that the class Foundation AR, ARSessionOrigin class doesn't recognise the Raycast method. According to their documentation it should do. Does anyone have any ideas.
    Ive tried the script on 2018.3.8 and 2019.1.3f1. I get other method to work such as MakeContentAppearAt. But the rays cast method is nowhere to be found (for me). please help!
     
  2. yolon3000

    yolon3000

    Joined:
    Aug 1, 2018
    Posts:
    10
    same question,can any one explain it ?
     
  3. n1ghtbird

    n1ghtbird

    Joined:
    Nov 6, 2018
    Posts:
    8
    Same issues on Unity 2019.1.0f2 with ARFoundation 2.1.

    I get the following errors appearing:
    'ARSubsystemManager' is missing in the current context
    'ARPlaneManager' does not contain definition for 'GetAllPlanes'
    'AROrigin' does not contain definition for 'Raycast'

    Have tried resetting the packages but to no avail.
     
  4. n1ghtbird

    n1ghtbird

    Joined:
    Nov 6, 2018
    Posts:
    8
    joshuaandre and albertoha94 like this.
  5. KelsoSharp

    KelsoSharp

    Joined:
    Feb 24, 2018
    Posts:
    3
    You need to create a raycast manager and use it instead of the ARSessionOrigin like this

    var hitsList = new List<ARRaycastHit>();
    var rayCastMgr = GetComponent<ARRaycastManager>();
    rayCastMgr.Raycast(screenCenter, hitsList, TrackableType.Planes);
     
    JDeyby, tackor and albertoha94 like this.
  6. ricardovalquin

    ricardovalquin

    Joined:
    Feb 19, 2019
    Posts:
    3
    Hi guys, thank you so much for the explanation, but a question for @KelsoSharp , calling the raycast manager and sending the TrackableType.Planes gives me an error:
    The name 'TrackableType' does not exist in the current context
    Is something that I need to import/define in the global scope?
    thank you so much
     
  7. maor_unity

    maor_unity

    Joined:
    Jun 11, 2018
    Posts:
    1
    did you manage to get it to work? im having the exact same problem
     
  8. markl_laha

    markl_laha

    Joined:
    Jun 29, 2018
    Posts:
    1
    added UnityEngine.XR.ARSubsystems; at the top since TrackableType seems to be associated to it, which is misleading since the migration guide explicitly said that the ARSubsystems manager has been removed. So I don't know if that's helped or if that's even the correct course of action, but it at least allows you to use TrackableType.
     
    leoagr likes this.
  9. ricardovalquin

    ricardovalquin

    Joined:
    Feb 19, 2019
    Posts:
    3
    Hi @markl_laha I already have that imported, now I'm getting this:

    NullReferenceException: Object reference not set to an instance of an object
    ArTabToPlace.UpdatePlacementPose () (at Assets/scripts/ArTabToPlace.cs:57)

    upload_2019-7-18_11-28-30.png

    and those are my imports:
    upload_2019-7-18_11-29-24.png
     
  10. ricardovalquin

    ricardovalquin

    Joined:
    Feb 19, 2019
    Posts:
    3

    Solved, added an Input manager to the ARSessionOrigin in the scene
     
    moogli likes this.
  11. faizan1990

    faizan1990

    Joined:
    Sep 30, 2019
    Posts:
    8
    I am sorry I am new to Unity, how exactly did you do that?
     
  12. mistergreen2016

    mistergreen2016

    Joined:
    Dec 4, 2016
    Posts:
    215
    There's a ARInputManager component. Add it to the AR Session Origin gameobject in your hierarchy.
     
  13. GreedyWorm

    GreedyWorm

    Joined:
    Apr 18, 2017
    Posts:
    1
    Did that but my indicator is still stuck where my phone is upon opening the app, any solutions?
     
  14. moogli

    moogli

    Joined:
    Feb 22, 2020
    Posts:
    1
    tnkss bro.. worked for me
     
  15. stuart-cupit

    stuart-cupit

    Joined:
    Feb 6, 2014
    Posts:
    1
    you need to initialise the raycastManager like this:

    void Start()
    {
    arOrigin = FindObjectOfType<ARSessionOrigin>();
    raycastManager = arOrigin.GetComponent<ARRaycastManager>();
    }

    then it worked for me.
     
  16. KirillKuzyk

    KirillKuzyk

    Joined:
    Nov 4, 2013
    Posts:
    170
    Here is an example on how to use ARRaycastManager.Raycast() method:
    Code (CSharp):
    1.  
    2. using System.Collections.Generic;
    3. using System.Linq;
    4. using UnityEngine;
    5. using UnityEngine.XR.ARFoundation;
    6. using UnityEngine.XR.ARSubsystems;
    7.  
    8.  
    9. public class RaycastExample: MonoBehaviour {
    10.     [SerializeField] ARSessionOrigin origin = null;
    11.     [SerializeField] ARRaycastManager raycastManager = null;
    12.     [SerializeField] TrackableType trackableTypeMask = TrackableType.Planes;
    13.  
    14.     Transform pointer;
    15.  
    16.  
    17.     void Awake() {
    18.         var sphere = GameObject.CreatePrimitive(PrimitiveType.Sphere).transform;
    19.         sphere.localScale = Vector3.one * 0.1f;
    20.         pointer = sphere.transform;
    21.     }
    22.  
    23.     void LateUpdate() {
    24.         var hit = raycast();
    25.         pointer.gameObject.SetActive(hit.HasValue);
    26.         if (hit.HasValue) {
    27.             pointer.position = hit.Value.pose.position;
    28.         }
    29.     }
    30.  
    31.     ARRaycastHit? raycast() {
    32.         var rayFromCameraCenter = origin.camera.ViewportPointToRay(new Vector3(0.5f, 0.5f));
    33.         var hits = new List<ARRaycastHit>();
    34.         if (raycastManager.Raycast(rayFromCameraCenter, hits, trackableTypeMask)) {
    35.             return hits.First();
    36.         } else {
    37.             return null;
    38.         }
    39.     }
    40. }
    41.  
     
    Last edited: Jun 24, 2020
unityunity