How to Detected AR Ojbect in AR Foundation

I have a Question.

I want raycasting to AR Ojbect But, not working code

AR Render :

void OnButtonClicked()
    {
        //var pose = EarthManager.CameraGeospatialPose;

        ARGeospatialAnchor anchor =
                 AnchorManager.AddAnchor(
                     22.612434,
                     122.14585,
                     35.15,
                     Quaternion.identity);
        anchor.name = "test1";
        Instantiate(GeospatialPrefab, anchor.transform);
        if (anchor != null)
        {
            GameObject anchorGO = Instantiate(GeospatialPrefab, anchor.transform);

            anchorGO.transform.parent = anchor.gameObject.transform;
            _anchorObjects.Add(anchor.gameObject);
            SnackBarText.text = GetDisplayStringForAnchorPlacedSuccess();
        }
        else
        {
            SnackBarText.text = GetDisplayStringForAnchorPlacedFailure();
        }
    }

RayCast :


```csharp
void Update()
    {       
        var earthTrackingState = EarthManager.EarthTrackingState;

        if (earthTrackingState == TrackingState.Tracking)
        {
            var pose = EarthManager.CameraGeospatialPose;
            InfoText.text = string.Format(
                "Latitude/Longitude: {1}°, {2}°{0}" +
                "Horizontal Accuracy: {3}m{0}" +
                "Altitude: {4}m{0}" +
                "Vertical Accuracy: {5}m{0}" +
                "Eun Rotation: {6}{0}" +
                "Orientation Yaw Accuracy: {7}°",
                Environment.NewLine,
                pose.Latitude.ToString("F6"),
                pose.Longitude.ToString("F6"),
                pose.HorizontalAccuracy.ToString("F6"),
                pose.Altitude.ToString("F2"),
                pose.VerticalAccuracy.ToString("F2"),
                pose.EunRotation.ToString("F1"),
                pose.OrientationYawAccuracy.ToString("F1"));
        }
        else
        {
            InfoText.text = "GEOSPATIAL POSE: not tracking";
        }
       

        if (Input.touchCount > 0)
        {
            Touch touch = Input.GetTouch(0);
            if (touch.phase == TouchPhase.Began)
            {
                Debug.Log("TouchBegan");
                Ray ray = arCamera.ScreenPointToRay(touch.position);
                RaycastHit hitObject;
                if (Physics.Raycast(ray, out hitObject))
                {
                    Debug.Log(hitObject.transform.gameObject.name); // Not Working

                }
            }                                

        }
       


    }

How to Fix This Code ?

It’s unclear from your post what you are trying to accomplish with this code. If you are trying to raycast against AR data in your scene provided by AR Foundation, you should use the raycast subsystem, not Physics.Raycast. AR Raycast Manager component | AR Foundation | 5.0.7

Physics.Raycast raycasts against colliders in your scene. ARRaycastManager.Raycast raycasts against the platform-provided AR data, using the AR trackable types that you specify.

Thank you for answer. I want get Object name. That’s why I used raycast.

The anchor created by this code

ARGeospatialAnchor anchor =
                 AnchorManager.AddAnchor(
                     22.612434,
                     122.14585,
                     35.15,
                     Quaternion.identity);
        anchor.name = "test1";
        Instantiate(GeospatialPrefab, anchor.transform);

I want to receive anchor information(anchor.name) when touched.

Can you answer me if you know?

I see. You cannot raycast against an anchor using ARRaycastManager.Raycast, so your instinct to use Physics.Raycast is probably correct for this use case. Just make sure that your GameObject has a Collider component on it and you should be able to raycast.