-
Notifications
You must be signed in to change notification settings - Fork 55
Settings system
The settings system allows researchers to assign parameters (e.g. independent variables) to the Session, a Block, or a Trial. The settings system is handled with a dedicated class: Settings.
Instances of a Session, Block, or Trial each contain a .settings field which is initially populated with an empty settings object.
When we begin the Session, we optionally pass a Settings object to be then used as the settings for the Session.
By default the Session is started using the UI, with a selected .json file ("Experiment profile") is deserialized. The deserialisation is performed by the popular MiniJSON script. When deserializing from .json, care must be taken when converting the type of the objects in our settings file.
The JSON is just a string - so MiniJSON interprets each value and attempts to deserialize it into an appropriate C# type.
| Example JSON | JSON type | C# cast example |
|---|---|---|
{"example": "hello"} |
string |
(string) settings["example"] |
{"example": 123} |
int |
(long) settings["example"] |
{"example": 3.14} |
float |
(double) settings["example"] |
{"example": [1, 2, 3]} |
array |
(List<object>) settings["example"] |
{"example": {"a": 1, "b": "hello"}} |
Dictionary<string, object> |
(Dictionary<string, object>) settings["example"] |
{"example": true} |
bool |
(bool) settings["example"] |
There are also ways to convert objects more directly to useful types found in unity (i.e. float and int). These are also less error prone - e.g. trying to deserialize { "example": 1 } with (long) settings["example"] would fail.
Note: Add using System; to the top of your script to gain access to the Convert.To*() methods.
| Example JSON | JSON type | Desired C# type | C# Conversion example |
|---|---|---|---|
{"example": 123} |
int |
int |
Convert.ToInt32(settings["example"]) |
{"example": 123} |
int |
float |
Convert.ToSingle(settings["example"]) |
{"example": 3.14} |
float |
float |
Convert.ToSingle(settings["example"]) |
If you have issues you can check validity of your JSON files with an online validator tool.
The setting system is set up such that, if a settings is unavailable, the request will cascade up the experiment hierarchy. For example, if a settings is not available for the Trial, it will look inside the Block, and then inside the Session.
๐ง 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