-
Notifications
You must be signed in to change notification settings - Fork 48
Session generation
Our Session
component contains our Block
objects, each of which contains Trial
objects. These need to be manually created and ordered in the way our experiment requires.
A common way to generate the blocks and trials for the session would be to call a method using the OnSessionBegin
UnityEvent that generates the blocks and trials for us.
Below is an example MonoBehaviour script that will perform the generation. With this script, you can then add GenerateExperiment
as a call within the On Session Begin
event.
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System.IO;
// add the UXF namespace
using UXF;
public class SessionGenerator : MonoBehaviour
{
public void GenerateExperiment(Session session)
{
// retrieve the n_practice_trials setting from the session settings
int numPracticeTrials = session.settings.GetInt("n_practice_trials");
// create block 1
Block practiceBlock = session.CreateBlock(numPracticeTrials);
practiceBlock.settings.SetValue("practice", true);
// retrieve the n_main_trials setting from the session settings
int numMainTrials = session.settings.GetInt("n_main_trials");
// create block 2
Block mainBlock = session.CreateBlock(numMainTrials); // block 2
// here we set a setting for the 2nd trial of the main block as an example.
mainBlock.GetRelativeTrial(2).settings.SetValue("size", 10);
mainBlock.GetRelativeTrial(2).settings.SetValue("color", Color.red);
// we enable a setting if this is the first session, e.g. to show instructions
session.GetTrial(1).settings.SetValue("show_instructions", session.number == 1);
// we can also do different things depending on participant information
int age = Convert.ToInt32(session.participantDetails["age"]);
session.settings.SetValue("sensitive_content", age >= 18);
}
}
You may wonder why there isn't an easy visual tool included in UXF to create trials. It is very common in human behaviour research to change the structure of the session in various different ways. For example, you may wish to randomise the order of your trials (using the built-in List<T>.Shuffle()
extension). You may also wish to add trials and blocks depending on lots of different conditions. UXF can't be expected to predict all these possibilities - so it currently requires manual, programmatic creation of blocks and trials. It being programmatic, of course means you are free to implement your own method of generating trials. They could be generated from a CSV file, or from some visual tool if someone wants to build one.
๐ง Core topics
- ๐ Background
- โจ UXF 2.0
- โ๏ธ Compatibility
- ๐ถ๏ธ Oculus Quest Setup
- ๐ญ Concepts
- ๐ ๏ธ Get started
- ๐ Examples
- ๐ฅ๏ธ Built-in UI
- ๐ Session generation
- โฐ Events
- ๐ Data collection
- โ๏ธ Collect custom data
- ๐ Custom Data Handler
- ๐ Remote Data Collection
- ๐๏ธ WebGL DynamoDB setup
- ๐ Processing DynamoDB CSVs
- ๐ซ HTTP Post Setup
- ๐ง Settings system
- ๐๐ฝ Tracker system
- ๐ Logging system
โ ๏ธ Common issues- ๐ผ๏ธ Multi-scene experiments
- ๐บ Videos
- ๐จโ๐ Full written tutorial
- ๐ฆ Asset links
- ๐จโ๐ซ Unity tutorial links
- ๐ Useful code snippets
- ๐ก Programming ideas
- ๐งฎ Example R processing