Search Unity

(Solved)Count AR Point Cloud number (AR Foundation 3.0.1)

Discussion in 'AR' started by Eric0x, Feb 12, 2020.

  1. Eric0x

    Eric0x

    Joined:
    Dec 26, 2019
    Posts:
    5
    (edited)
    Problem Solved!
    just properly assign ARSessionOrigin and it works



    Hi all.
    I have been trying to count the number of all ar point cloud collected in the AR session

    I've tried the following code. But arPointCloud keeps throwing error message: Object reference not set to an instance of an object

    I would be so happy if anyone can help me. :eek:

    Thanks!

    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4. using UnityEngine.UI;
    5. using UnityEngine.XR.ARFoundation;
    6.  
    7.  
    8. public class PointNumberCount : MonoBehaviour
    9. {
    10.     ARSessionOrigin arSessionOrigin;
    11.     ARPointCloud arPointCloud;
    12.  
    13.     int totalNumber;
    14.     List<Vector3> featurePoints = new List<Vector3>();
    15.  
    16.     void Start()
    17.     {
    18.    
    19.         arSessionOrigin = GetComponent<ARSessionOrigin>();
    20.    
    21.         arPointCloud = arSessionOrigin.trackablesParent.GetComponentInChildren<ARPointCloud>();
    22.     }
    23.     void Update()
    24.     {
    25.    
    26.             arPointCloud = arSessionOrigin.trackablesParent.GetComponentInChildren<ARPointCloud>();
    27.             featurePoints = new List<Vector3>(arPointCloud.positions);
    28.             totalNumber = featurePoints.Count;
    29.  
    30.     }
    31. }
    32. }
     
    Last edited: Feb 14, 2020
    unnanego likes this.