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

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!

same question,can any one explain it ?

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.

I was kindly helped by @ on GitHub on ARFoundation samples.

Follow this guide to make the appropriate changes:
https://docs.unity3d.com/Packages/com.unity.xr.arfoundation@2.0/manual/migration-guide.html

2 Likes

You need to create a raycast manager and use it instead of the ARSessionOrigin like this

var hitsList = new List();
var rayCastMgr = GetComponent();
rayCastMgr.Raycast(screenCenter, hitsList, TrackableType.Planes);

3 Likes

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

did you manage to get it to work? im having the exact same problem

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.

5 Likes

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)

and those are my imports:
4760903--452468--upload_2019-7-18_11-29-24.png

Solved, added an Input manager to the ARSessionOrigin in the scene

1 Like

I am sorry I am new to Unity, how exactly did you do that?

There’s a ARInputManager component. Add it to the AR Session Origin gameobject in your hierarchy.

Did that but my indicator is still stuck where my phone is upon opening the app, any solutions?

tnkss bro… worked for me

you need to initialise the raycastManager like this:

void Start()
{
arOrigin = FindObjectOfType();
raycastManager = arOrigin.GetComponent();
}

then it worked for me.

Here is an example on how to use ARRaycastManager.Raycast() method:

using System.Collections.Generic;
using System.Linq;
using UnityEngine;
using UnityEngine.XR.ARFoundation;
using UnityEngine.XR.ARSubsystems;


public class RaycastExample: MonoBehaviour {
    [SerializeField] ARSessionOrigin origin = null;
    [SerializeField] ARRaycastManager raycastManager = null;
    [SerializeField] TrackableType trackableTypeMask = TrackableType.Planes;

    Transform pointer;


    void Awake() {
        var sphere = GameObject.CreatePrimitive(PrimitiveType.Sphere).transform;
        sphere.localScale = Vector3.one * 0.1f;
        pointer = sphere.transform;
    }

    void LateUpdate() {
        var hit = raycast();
        pointer.gameObject.SetActive(hit.HasValue);
        if (hit.HasValue) {
            pointer.position = hit.Value.pose.position;
        }
    }

    ARRaycastHit? raycast() {
        var rayFromCameraCenter = origin.camera.ViewportPointToRay(new Vector3(0.5f, 0.5f));
        var hits = new List<ARRaycastHit>();
        if (raycastManager.Raycast(rayFromCameraCenter, hits, trackableTypeMask)) {
            return hits.First();
        } else {
            return null;
        }
    }
}
1 Like

When you have problems with “missing” commands in scripts it seems to be because of incompatible packages. Go to the Package Manager and see which packages are not “Verified” or have dependency conflicts.

First() isn’t an available function of List — Unless I am missing something. hits[0] would do the same thing. Kinda wish ‘First’ was an option since it looks cleaner.

First() is an extension method. Please import the System.Linq to use it:
using System.Linq;

Nice, thanks