BioMotionLab / TUX

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

How to access ExperimentRunnerUI (Debug/Start Experiment) after building project to an application? #29

Closed n3urovirtual closed 2 years ago

n3urovirtual commented 3 years ago

Hi,

I have built my project into an application and the scene environment is loaded properly while the UI to start the experiment is not. In the editor, everything works fine, as I have the scene environment on display 1 and the UI in display 2. I also managed to make it work with a WMR HMD (in the editor). I have read the "Building to an application" section on the bmltux website but it was not so informative on that matter. Is there a way to start the experiment after building a project? I was wondering if I could preload some scene environments (tasks) into a standalone VR HMD and have participants complete them without my assistance. Is this sth that could be done using the toolkit?

Many thanks and keep up the great work.

AdamBebko commented 3 years ago

Hi Christos, I’m currently on vacation so I can’t access the project. There’s a simple C# event that is triggered when you press the start experiment button. All you need to do is to trigger that same event through code or some other means to start the experiment. I can’t remember off the top of my head the name. But it’s probably something like TuxEvents.StartExperiment.

Sent from my iPhone

On Aug 8, 2021, at 2:06 PM, Christos Gkoumas @.***> wrote:

 Hi,

I have built my project into an application and the scene environment is loaded properly while the UI to start the experiment is not. In the editor, everything works fine, as I have the scene environment on display 1 and the UI in display 2. I also managed to make it work with a WMR HMD (in the editor). I have read the "Building to an application" section on the bmltux website but it was not so informative on that matter. Is there a way to start the experiment after building a project? I was wondering if I could preload some scene environments (tasks) into a standalone VR HMD and have participants complete them without my assistance. Is this sth that could be done using the toolkit?

Many thanks and keep up the great work.

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub, or unsubscribe. Triage notifications on the go with GitHub Mobile for iOS or Android.

AdamBebko commented 2 years ago

Did you get this working?

n3urovirtual commented 2 years ago

Hi Adam,

No, I didn't. I found the Events you were talking about but I couldn't get it to work. What I have now is this:

using bmlTUX.Scripts.Managers;
using bmlTUX.Scripts.ExperimentParts;
using UnityEngine;
using bmlTUX.Scripts.UI.RuntimeUI;

public class StartExperiment : MonoBehaviour
{

    // Update is called once per frame
    void Update()

    {
        if (Input.GetKeyDown("space"))
        {
            Session session = new DebugSession();
            Debug.Log("I am gonna make it work");
            StartRunningExperiment(session);
        }

    }

    void StartRunningExperiment(Session session)
    {
        ExperimentEvents.StartRunningExperiment(session);
    }
}

Any help is much appreciated.

AdamBebko commented 2 years ago

Right, so now that I'm home and looking at the code I'm seeing there's some complication there. Definitely not ideal. Let me take a look and get back to you

n3urovirtual commented 2 years ago

Sure. When I tried to track down what the issue was I remember having issues with referencing because some of the classes were not public. I don't know if this helps you somehow.

AdamBebko commented 2 years ago

Ok so in the meantime, this seems to work. I will look into making this a bit more user friendly when I release the next version.

   // Update is called once per frame
    void Update()

    {
        if (Input.GetKeyDown("space"))
        {
            Session session = new DebugSession();

            //if you have participant variables
            //foreach (ParticipantVariable variable in runner.DesignFile.GetVariables.ParticipantVariables) {
            //    variable.SetValueDefaultValue();
            //}

            ExperimentGui experimentStartPanel = FindObjectOfType<ExperimentGui>();
            experimentStartPanel.gameObject.SetActive(false);
            Debug.Log("I am gonna make it work");
            StartRunningExperiment(session);

            Destroy(this.gameObject);
        }

    }
AdamBebko commented 2 years ago

Sorry, need to add the line Destroy(this.gameObject) to avoid spamming errors. I edited above post

n3urovirtual commented 2 years ago

Hi Adam, Thanks for your prompt reply. Unfortunately, the code you posted doesn't work either. I am getting an error for ExperimentGui and the StartRunningExperiment method. Is this a namespace issue?

Update: ExperimentGui error goes away if you add using bmlTUX.Scripts.UI.RuntimeUI;

AdamBebko commented 2 years ago

Here are the namespaces I am using. Sorry, that's something else I need to fix, I forget that most of the world doesn't use Rider IDE.

using bmlTUX.Scripts.Managers; using bmlTUX.Scripts.ExperimentParts; using UnityEngine; using bmlTUX.Scripts.UI.RuntimeUI;

n3urovirtual commented 2 years ago

It still doesn't work. StartRunningExperiment is red and says it does not exist in the current context. Also using bmlTUX.Scipts.Managers; is gray like it is not being used in this script.

AdamBebko commented 2 years ago

Do you have the script it in an assembly? Maybe you need to reference a different assembly? Or just put it directly in your assets folder with no assemblies? Or try rebooting Unity/your IDE.

it works for me with those using statements.

n3urovirtual commented 2 years ago

I added ExperimentEvents.StartRunningExperiment(session) and it's fine now. I'm gonna test it using VR.

Update: It works in my WMR headset. Thanks a lot @AdamBebko!

AdamBebko commented 2 years ago

Great! And thanks for the feedback, Hopefully I can clean up that workflow in the next version.

AdamBebko commented 2 years ago

There is a new event for triggering the experiment to start based on a provided session

How to do this now:


Session session = new Session() //You create your session manually. Has to be a valid session.
ExperimentEvents.StartExperimentFromScript(session);

Behind the scenes:

//UI listens to this event and hides itself when it happens automatically.
public static event TriggerStartExperimentWithoutButtonEvent ExperimentTriggeredWithoutButton;

//Wraps call to StartRunningExperiment so rest of program can gracefully know that it's not happening from GUI.
[PublicAPI]
public static void StartExperimentFromScript(Session session)
{
    ExperimentTriggeredWithoutButton?.Invoke(session);
    StartRunningExperiment(session);
}