AR Path Display Issue: Path Not Showing on Screen Tap

Hello everyone!
I’m working on an AR-based indoor navigation app and using this script to display the path. Additionally, I’ve added this script to the indicator.

using UnityEngine;
using UnityEngine.AI;

public class SetNavigationTarget : MonoBehaviour
{
    [SerializeField]
    private Camera TopDownCamera;
    [SerializeField]
    private GameObject NavTargetObject;
    private NavMeshPath path; // current calculated path
    private LineRenderer Line; // LineRender to display path
    private bool LineToggle = false;

    private void Start()
    {
        path = new NavMeshPath();
        Line = transform.GetComponent<LineRenderer>();
    }

    private void Update()
    {
        if ((Input.touchCount > 0)&&(Input.GetTouch(0).phase==TouchPhase.Began))
        {
            LineToggle = !LineToggle;
        }
        if (LineToggle)
        {
            NavMesh.CalculatePath(transform.position, NavTargetObject.transform.position, NavMesh.AllAreas, path);
            Line.positionCount = path.corners.Length;
            Line.SetPositions(path.corners);
            Line.enabled = true;
        }
    }
}

However, after building and testing the app, the path doesn’t appear when I tap the screen. What could be causing this issue?

Sounds like you wrote a bug… and that means… time to start debugging!

I would start by spewing those line coordinates to a debug window you can view in the app. Odds are they are not what you think they are. If they are, then start looking at why it might not be getting rendered, looking for shader issues, layering issues, etc.

By debugging you can find out exactly what your program is doing so you can fix it.

Use the above techniques to get the information you need in order to reason about what the problem is.

You can also use Debug.Log(...); statements to find out if any of your code is even running. Don’t assume it is.

Once you understand what the problem is, you may begin to reason about a solution to the problem.

Remember with Unity the code is only a tiny fraction of the problem space. Everything asset- and scene- wise must also be set up correctly to match the associated code and its assumptions.