Unable to detect plane Indicator

Hello everyone,
Hope this message finds you well,

I have a problem with my Augmented reality app, I’m unable to see my placement indicator

Here’s my code:

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

public class ARTapToPlaceObject : MonoBehaviour
{
    public GameObject objectToPlace;
    public GameObject placementIndicator;
    private ARSessionOrigin arOrigin;
    private Pose placementPose;
    private bool placementPoseIsValid = false;
    private ARRaycastManager raycastManager;
    // Start is called before the first frame update
    void Start()
    {
        arOrigin = FindObjectOfType<ARSessionOrigin>();
        raycastManager = FindObjectOfType<ARRaycastManager>();

    }

    // Update is called once per frame
    void Update()
    {
        UpdatePlacementPose();
        UpdatePlacementIndicator();

        if(placementPoseIsValid && Input.touchCount > 0 && Input.GetTouch(0).phase == TouchPhase.Began) {
            PlaceObject();
        }
    }

    private void PlaceObject()
    {
        Instantiate(objectToPlace, placementPose.position, placementPose.rotation);
    }

    private void UpdatePlacementIndicator()
    {
        if(placementPoseIsValid)
        {
            placementIndicator.SetActive(true);
            placementIndicator.transform.SetPositionAndRotation(placementPose.position, placementPose.rotation);
        }
        else
        {
            placementIndicator.SetActive(false);
        }
    }

    private void UpdatePlacementPose()
    {
        raycastManager = FindObjectOfType<ARRaycastManager>();
        var screenCenter = Camera.current.ViewportToScreenPoint(new Vector3(0.5f, 0.5f));
        var hits = new List<ARRaycastHit>();
        raycastManager.Raycast(screenCenter, hits, TrackableType.Planes);

        placementPoseIsValid = hits.Count > 0;

        if(placementPoseIsValid)
        {
            placementPose = hits[0].pose;

            var cameraForward = Camera.current.transform.forward;
            var cameraBearing = new Vector3(cameraForward.x, 0, cameraForward.z).normalized;
            placementPose.rotation = Quaternion.LookRotation(cameraBearing);
        }
    }
}

And here’s my scene images


Kind regards,

Any solution?

There doesn’t seem to be any obvious problems with the code that you provided that would cause the placement indicator to not appear. However, it’s possible that the issue could be caused by something outside of this script, such as the configuration of the ARSession, the lighting conditions in your environment, or the size of the object that you’re trying to place.

Here are a few things you can check:

  • Make sure that the placementIndicator object is assigned in the inspector, and that it’s set to be active by default.

  • Check that the placementIndicator object is not being blocked by another object in the scene. Try moving the camera around to see if the placement indicator appears from a different angle.

  • Ensure that there are surfaces in the camera view that can be detected by the AR system. Try moving the camera around to different areas and see if the placement indicator appears in a different location.

  • Check if there are any errors or warnings in the console that could be related to the issue.

  • Try increasing the size of the placementIndicator object to make it more visible.

If none of these suggestions work, you may want to try creating a new, simple AR project with just the placement indicator and see if it appears correctly. This can help isolate the issue and determine if it’s related to the code or something else.

1 Like

@mujahid077 Thank you for your response,
None of the above helped me,
I have figured it out by adding a new component to the ARSessionOrigin “AR Plane Manager” and by this it has been fixed :slight_smile:

1 Like

I’m glad to hear that you were able to resolve the issue by adding the “AR Plane Manager” component to the ARSessionOrigin. This component is responsible for detecting flat surfaces in the camera view and creating ARPlane objects in the scene.

Adding this component can be helpful if your app requires the user to place objects on a flat surface, as it allows the app to detect and display the surface in real-time.

2 Likes