Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Error converting TrackableType

Discussion in 'AR/VR (XR) Discussion' started by ben0ki, Jul 4, 2019.

  1. ben0ki

    ben0ki

    Joined:
    Oct 30, 2017
    Posts:
    13
    I keep getting the following error around TrackableType in my demo script:

    ARTapToPlaceObject.cs(46,46): error CS1503: Argument 3: cannot convert from 'UnityEngine.Experimental.XR.TrackableType' to 'UnityEngine.XR.ARSubsystems.TrackableType'


    Anyone know the solution?

    Script:


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

    public class ARTapToPlaceObject : MonoBehaviour
    {
    public GameObject placementIndicator;

    private ARRaycastManager arOrigin;
    private Pose placementPose;
    private bool placementPoseIsValid = false;

    void Start()
    {
    arOrigin = FindObjectOfType<ARRaycastManager>();
    }

    void Update()
    {
    UpdatePlacementPose();
    UpdatePlacementIndicator();
    }

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

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

    placementPoseIsValid = hits.Count > 0;
    if (placementPoseIsValid)
    {
    placementPose = hits[0].pose;
    }
    }
    }
     
    Last edited: Jul 4, 2019
  2. ben0ki

    ben0ki

    Joined:
    Oct 30, 2017
    Posts:
    13
    For anyone who has the same problem, the issue is related to version compatibility.. The handy youtube example I was following to write the above script was created using the following versions:



    AR Foundation [1.0.0-preview.22] - 2018-12-13
    ARCore XR Plugin [1.0.0-preview.24] - 2018-12-13
    ARKit XR Plugin [1.0.0-preview.20] - 2018-12-13
    Unity 2018.3.14f1
    Xcode 10.2.1 (10E1001)
    macOS 10.14.6 (18G29g)

    As per this post: https://github.com/TheUnityWorkbench/tuw-arfoundation-demo/issues/2

    I was able to get the code working by reverting back to the above Unity + package versions. You can download the older Unity version through Unity Hub, and the packages can be found here if you can't access them through package manager (https://unitypack.herokuapp.com/).


    Unfortunately there don't seem to be any equivalent tutorials/guides at the moment for the latest 2.0+ versions. There is a migration guide (https://docs.unity3d.com/Packages/com.unity.xr.arfoundation@2.2/manual/migration-guide.html) but I couldn't figure it out.
     
  3. hohlfeldw

    hohlfeldw

    Joined:
    Jul 16, 2019
    Posts:
    1
    Hey,

    just use another import:

    using UnityEngine.XR.ARSubsystems;

    instead of

    using UnityEngine.Experimental.XR;

    Then it should work =)



    Here is my whole code that works:

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

    public class ARTapToPlaceObject : MonoBehaviour
    {
    public GameObject placementIndicator;

    private ARRaycastManager arRaycastManager;
    private Pose placementPose;
    private bool placementPoseIsValid = false;

    // Start is called before the first frame update
    void Start()
    {
    arRaycastManager = FindObjectOfType<ARRaycastManager>();
    }

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

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

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

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

    faizan1990

    Joined:
    Sep 30, 2019
    Posts:
    8
    My camera is not detecting the plane and not showing the yellow arrow to start with. Using samsung galaxy s9+
     
  5. Dikkesnoek

    Dikkesnoek

    Joined:
    Nov 10, 2017
    Posts:
    1
    Thanks. The Error has been gone.
     
  6. montanhabio

    montanhabio

    Joined:
    Aug 8, 2020
    Posts:
    6
    Thank you. Finished Error
     
  7. Ram-Apprlabs

    Ram-Apprlabs

    Joined:
    Apr 19, 2022
    Posts:
    10
    The name 'TrackableType' does not exist in the current context
     
  8. lulitha

    lulitha

    Joined:
    Feb 8, 2017
    Posts:
    9
    You saved me. thank you