Unity plugin: managing conditions
A primary feature of the VERA Unity plugin is the ability to manage experimental conditions / independent variables in your Unity experiments.
Key takeaways
For each independent variable defined on the VERA portal, a corresponding C# class is automatically generated in the VERA Unity plugin.
This class is named VERAIV_[IVName].
This class contains a GetSelectedValue() and SetSelectedValue(IVValue value) method.
There is a single preprocessor directive for each independent variable, which can be used to conditionally compile code related to that independent variable.
All data logged will automatically include the current values of all IVs as a column.
// EXAMPLE USAGE OF CONDITION MANAGEMENT WITH VERA
// This code conditionally compiles only if the "WeatherType" independent variable is being used in the experiment
#if VERAIV_WeatherType
// Get the current value of the "WeatherType" independent variable
VERAIV_WeatherType.IVValue currentValue = VERAIV_WeatherType.GetSelectedValue();
// Set the current value of the "WeatherType" independent variable to "Sunny"
VERAIV_WeatherType.SetSelectedValue(VERAIV_WeatherType.IVValue.Sunny);
#endif
Understanding independent variables and conditions
In experimental design, an independent variable is a variable that is manipulated or controlled by the experimenter to observe its effect on a dependent variable. Independent variables are often used to test hypotheses and determine causal relationships between variables. In the context of XR experiments, independent variables might include factors such as the type of interaction method used (e.g., hand tracking vs. controller input), the level of immersion (e.g., high vs. low), or the presence of certain environmental cues (e.g., visual vs. auditory).
The experimental conditions refer to the specific values or settings of the independent variables that participants are exposed to during the experiment.
In VERA, each experiment can define multiple independent variables. Each of these independent variables can be set to different values during the experiment. The combination of these independent variables and their values defines the experimental conditions.
For example, consider an experiment which examines the effect of weather type and time of day on user performance in an XR task. In this experiment, there are two independent variables: weather type and time of day. The weather type independent variable has three possible values: sunny, rainy, and snowy. The time of day independent variable has two possible values: day and night. This results in a total of six possible experimental conditions: sunny day, sunny night, rainy day, rainy night, snowy day, snowy night.
VERAIVs in Unity
Any Independent Variables (IVs) you define for your experiment on the VERA web interface will be accessible in the VERA Unity plugin. For more information on defining IVs for your experiment, see the Web interface: overview section.
When you select an active experiment in the VERA Unity plugin, C# code is automatically generated for each of the experiment’s IVs. This code is stored in the Assets > VERA > Conditions > GeneratedCode folder in your Unity project.
There will always be a single C# class generated for each independent variable defined in your experiment. These classes can be used to get or set the value of a particular independent variable during the experiment.
Each of these generated files is named according to its corresponding independent variable. The class is prefixed by “VERAIV_”, followed by the name of the particular independent variable as defined on the VERA web interface. For example, if you have an independent variable named “MyIV”, the generated class will be named “VERAIV_MyIV”.
For each of these generated classes, there is an enum which represents all possible values for that independent variable. For example, if you have an independent variable named “WeatherType” with possible values “Sunny”, “Rainy”, and “Snowy”, the generated enum will be named “VERAIV_WeatherType.IVValues”, and will contain the values Sunny, Rainy, and Snowy.
Preprocessor directives
Preprocessor directives are used to conditionally compile code based on certain conditions. This can be useful for ensuring that code related to a specific feature, version, or configuration is only compiled when that feature, version, or configuration is being used.
In the VERA Unity plugin, every generated C# class for an independent variable comes with a single preprocessor directive. In this way, you can ensure that code related to a specific IV is only compiled when you are using that IV in your experiment. This can be useful if you plan to swap experiments often, to prevent compiler errors related to missing IVs.
These preprocessor directives are named according to their corresponding independent variable. For example, if you have an independent variable named “VERAIV_MyIV”, the generated directive will be named “VERAIV_MyIV”.
// Example usage of a preprocessor directive for a VERA independent variable
#if VERAIV_MyIV
// Code related to the "MyIV" independent variable goes here
// This code will only be compiled if the "MyIV" independent variable is being used
#endif
Getting and setting IV values
To get or set the value of a particular independent variable in your Unity experiment, you can use the generated C# class for that IV. Each generated class contains two static methods:
GetSelectedValue(): Returns the current value of the independent variable as an enum value.
SetSelectedValue(IVValue newValue): Sets the independent variable to the specified value.
// Example of getting and setting an independent variable value
// This example uses an independent variable named "WeatherType", which has possible values "Sunny", "Rainy", and "Snowy"
#if VERAIV_WeatherType
// Get the current value of the WeatherType independent variable
VERAIV_WeatherType.IVValue currentWeather = VERAIV_WeatherType.GetSelectedValue();
// Set the WeatherType independent variable to "Rainy"
VERAIV_WeatherType.SetSelectedValue(VERAIV_WeatherType.IVValue.Rainy);
#endif
If you properly set your independent variable values / experimental conditions during your experiment, these values will automatically be logged as a single column entry in every CSV file type you log data to (see the Unity plugin: logging data section for more details). In this way, any data you record during an experiment can be associated with the experimental conditions the participant was under at the time.
Next steps
Next, consider exploring the Unity plugin: logging data section, which explains how to log CSV data during your Unity experiments using the VERA plugin. Additionally, consider exploring the Unity plugin: managing sessions section, which explains how to manage participant sessions in your Unity experiments using the VERA plugin.
For a quick reference guide to using the VERA Unity plugin, which includes a list of the functions outlined above, see the Unity plugin: quick reference section.