BioMotionLab / TUX

A framework for experiments in Unity and VR
https://biomotionlab.github.io/TUX/
Other
29 stars 4 forks source link

Will this work on standalone VR headsets? #33

Closed A-Ivan closed 2 years ago

A-Ivan commented 2 years ago

Hi @AdamBebko ,

I may have missed this in the documentation, but from what I understand bmlTUX works both running in the Unity Editor (where 1 or 2 game windows can be used, when choosing 2 windows, one game window for the participant to visualize the stimulus - which can be presented on a computer monitor or a VR headset, and another game window for the researcher to keep track of the study's progress), or be built to an executable which will only have one window, the participant's. Is this correct so far?

Would it be possible to use a standalone VR headset (running Android), for instance the Oculus Quest, for a study, without the Quest being connected to a computer? If so, where would I be able to find the csv files that are generated during the study?

Thank you, Ivan

AdamBebko commented 2 years ago

I haven’t used standalone HMDs myself. But I know you’ll have to create a custom display settings asset and link to it in the design file. In that setting asset there are options to hide the runner screen, so you just start the experiment and then hand it to the participant. You should probably do a “ready check” in your pre-experiment coroutine, so the participant can go forward and start when ready. We have also used compiled executables in a 2-monitor setup and 1monitor/1hmd setup without any problems. It just follows your settings in the display settings asset.

Unfortunately I have no idea where you could retrieve the CSV files from a standalone HMD. But you can choose any save path in the startup window, so hopefully you can find a place to save where you can later access the data. If you look through some of the other Issues posts on here, you’ll see some other users that have successfully implemented it on standalone systems, you might shoot them a message and ask how they did it.

A-Ivan commented 2 years ago

Great to hear this may also work for standalone headsets. I thought there would be an issue with permission and writing to a file. I will take a look at the other posts to see what others have done, thanks.

n3urovirtual commented 2 years ago

@A-Ivan this is also sth I am really interested in using a Pico headset. Happy to discuss further.

A-Ivan commented 2 years ago

Hi @n3urovirtual ,

I do not currently have a Quest with me to test, and since the Pico also uses Android, this solution may work with both.

It seems that as long as the function to save the csv file is using "Application.persistentDataPath", then it should work and save to "/storage/emulated/0/Android/data//files"- https://docs.unity3d.com/ScriptReference/Application-persistentDataPath.html

These files would need to be accessed by connecting the device to a computer and manually copying those files over to the computer.

There may be some write permissions to set though (Unity Editor Menu -> Edit -> Project Settings -> Player -> Write Permission) - https://forum.unity.com/threads/writing-files-to-oculus-quest.1076615/

You may have to play around with these options (Internal and External write) to see what works.

image

n3urovirtual commented 2 years ago

Hi @A-Ivan,

This is amazing! Thanks for sharing. Currently, I don't have a standalone headset either but I will probably play around with it sometime in October/November. I will let you know how it goes.

A-Ivan commented 2 years ago

Hi @n3urovirtual ,

You're welcome. I believe this should work. Great, let me know how it goes. If I am able to test it on my side I'll also report back.

A-Ivan commented 2 years ago

Hi @n3urovirtual ,

I talked to other some people about this and setting the writing permission to external and using "Application.persistentDataPath" should allow for writing on Android devices (this includes both Android for mobile devices and Android for VR headsets like Oculus, and I assume also includes Pico). Using persistentDataPath also works for iOS and others.

I created a script to help change the write permission to external automatically. I incorporated it within another script I wrote before, used to setup API Compatibility Level and Scripting Runtime Version.

I also added some code to automatically setup Windows and Oculus Quest build (minimum Android API level, target Android API level, write permission to external, texture compression). Since I wasn't able to clearly find this setup information online for the Pico, you can just use the Android setup and manually set those up as needed.

You just need to add this script, called "AutomaticallyConfigureSettings", to your Assets folder in Unity, I suggest a "Scripts" folder to make it more organized.

In the Unity Editor, a Menu option will appear, called "bmITUX", with the sub-options called "Android Setup For bmITUX Use" and "Oculus Quest Setup For bmITUX Use", clicking on these options will automatically setup the settings for either Android (Android mobile devices) or Oculus Quest, respectively. Note, it takes around 10 seconds for the Unity Editor to update these settings (at least on my computer).

image

using UnityEngine;
using UnityEditor;

public class AutomaticallyConfigureSettings : MonoBehaviour
{
    [MenuItem("bmITUX/Windows Setup For bmITUX Use")]
    private static void SetSettingsWindows()
    {
        // Switch to Windows 64-bit build.
        EditorUserBuildSettings.SwitchActiveBuildTarget(BuildTargetGroup.Standalone, BuildTarget.StandaloneWindows64);

        // If the current build target is Windows, then set
        if (EditorUserBuildSettings.activeBuildTarget == BuildTarget.StandaloneWindows64)
        {            
            // Setup common settings
            CommonSettings();

            Debug.Log("Windows settings set");
        }

        // If the build target was not set to Windows (it may not be available on the system)
        else
        {
            Debug.Log("Windows build was not set, check if it is available. If it isn't, add it to the Unity Editor version via the Unity Hub.");
        }
    }

    [MenuItem("bmITUX/Android Setup For bmITUX Use")]
    private static void SetSettingsAndroid()
    {
        // Switch to Android build.
        EditorUserBuildSettings.SwitchActiveBuildTarget(BuildTargetGroup.Android, BuildTarget.Android);

        // If the current build target is Android, then set the write permission to external
        if (EditorUserBuildSettings.activeBuildTarget == BuildTarget.Android)
        {
            // Changes Android write permission to external
            PlayerSettings.Android.forceSDCardPermission = true;

            // Sets the Texture Compression to Default (Don't override)
            EditorUserBuildSettings.androidBuildSubtarget = MobileTextureSubtarget.Generic;

            // Setup common settings
            CommonSettings();

            Debug.Log("Android settings set");
        }

        // If the build target was not set to Android (it may not be available on the system)
        else
        {
            Debug.Log("Android build was not set, check if it is available. If it isn't, add it to the Unity Editor version via the Unity Hub.");
        }
    }

    [MenuItem("bmITUX/Oculus Quest Setup For bmITUX Use")]
    private static void SetSettingsOculus()
    {
        // Switch to Android build.
        EditorUserBuildSettings.SwitchActiveBuildTarget(BuildTargetGroup.Android, BuildTarget.Android);

        // If the current build target is Android, then set the write permission to external, and configure API levels and Texture compression
        if (EditorUserBuildSettings.activeBuildTarget == BuildTarget.Android)
        {
            // Changes Android write permission to external
            PlayerSettings.Android.forceSDCardPermission = true;

            // Sets the Android API Level to 26
            PlayerSettings.Android.minSdkVersion = AndroidSdkVersions.AndroidApiLevel26;

            // Sets the Android API Level to Automatic (highest installed)
            PlayerSettings.Android.targetSdkVersion = AndroidSdkVersions.AndroidApiLevelAuto;

            // Sets the Texture Compression to ASTC
            EditorUserBuildSettings.androidBuildSubtarget = MobileTextureSubtarget.ASTC;

            // Setup common settings
            CommonSettings();

            Debug.Log("Oculus settings set");
        }

        // If the build target was not set to Android (it may not be available on the system)
        else
        {
            Debug.Log("Android build was not set, check if it is available. If it isn't, add it to the Unity Editor version via the Unity Hub.");
        }
    }

    // This sets up the API Compatibility Level and the Scripting Runtime Version
    private static void CommonSettings()
    {
        // Sets the Build Target Group to be the current build target group (required) and the API Compatibility Level to be .NET 4.6
        PlayerSettings.SetApiCompatibilityLevel(EditorUserBuildSettings.selectedBuildTargetGroup, ApiCompatibilityLevel.NET_4_6);

        // Only set the Scripting Runtime Version if the Unity version is 2019 (as scripting runtime version was deprecated as of 2020)
        if (Application.unityVersion.Contains("2019"))
        {
            PlayerSettings.scriptingRuntimeVersion = ScriptingRuntimeVersion.Latest;
        }

        Debug.Log("API Compatibility set to .NET 4.x and Scripting Runtime Version set to .Net 4.x Equivalent. Setup complete.");
    }
}

I hope this helps.

AdamBebko commented 2 years ago

as mentioned elsewhere this ticket will be addressed by adding a standalone headset section to the docs. Will update as I make progress.

AdamBebko commented 2 years ago

linking people to this channel from docs.