Exporting Log Data from Oculus Quest with CSV file format

Hi,

When I tried to extract log data from desktop version, it worked well with this code:

using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using UnityEngine;

public class PositionData : MonoBehaviour
{
    [Header("CSV File Name")]
    [SerializeField] string csvName;

    [Header("OVRCameraRig")]
    [SerializeField] GameObject player;

    private string participantID;
    private string filePath;
    private bool startWriting;
    private bool canRecord;

    private void Start()
    {
        participantID = PlayerPrefs.GetString("ID", "INVALID");
        startWriting = false;
        canRecord = true;
        filePath = GetFilePath();
    }

    private void Update()
    {
        if (canRecord)
        {
            addRecord(participantID, Time.time, player.transform.position.x, player.transform.position.z, filePath);
            StartCoroutine(delayRecord());
        }
    }

    private void addRecord(string ID, float time, float x, float z, string filePath)
    {
        print("Writing to file");
        try
        {
            if (!startWriting)
            {
                using (StreamWriter file = new StreamWriter(@filePath, false))
                {
                    file.WriteLine("UserID" + "," + "Time" + "," + "XPos" + "," + "ZPos");
                }
                startWriting = true;
            }
            else
            {
                using (StreamWriter file = new StreamWriter(@filePath, true))
                {
                    file.WriteLine(ID + "," + time + "," + x + "," + z);
                }
            }
        }
        catch (Exception ex)
        {
            Debug.Log("Something went wrong! Error: " + ex.Message);
        }
    }

    private IEnumerator delayRecord()
    {
        canRecord = false;
        yield return new WaitForSeconds(0.2f);
        canRecord = true;
    }

    string GetFilePath()
    {
        return Application.dataPath + "/"  + "_" + csvName + ".csv";
    }
}

However, if I build and launch this app with my Oculus Quest headset, then it does not generate csv file. I connected Quest to the desktop with a wire cable (and cable seems work well because I can build apps with this setting).

Can anyone help me with this?

Hey, thank you for sharing the code.

For it to work on the Oculus Quest, you can change the “Application.dataPath” to “Application.persistentDataPath”. The csv file is going to be saved in /sdcard/Android/data/com.oculus.XXX/files (with com.oculus.XXX is your Package Name).

Another issue that might happen is that for the player GameObject, you need to reference a camera of the OVRCameraRig, e.g. CenterEyeAnchor for the position data to be recorded. At first, I referenced the OVRCameraRig and the position data remained the same.

1 Like