immersivecognition / unity-experiment-framework

UXF - Framework for creating human behaviour experiments in Unity
https://immersivecognition.github.io/unity-experiment-framework/
MIT License
214 stars 41 forks source link

Add the option to change from relative time (i.e. Time.time) to system time for trackers #118

Closed JAQuent closed 6 days ago

JAQuent commented 2 years ago

Would it be possible to add the possibility to give people the option to use system time time-stamps for UXF pre-written trackers (e.g. the position trackers) as it would be very useful for neuroimaging research (as explained in this issue (https://github.com/immersivecognition/unity-experiment-framework/issues/117).

I know I could just create a custom script that not only saves x, y and z position and rotation but also add system time in the case of the position tracker but I am wondering whether it is possible to change the existing script to change this on higher level.

However, one question is: Would there be more impact on peformance if use save system as opposed to relative time?

jackbrookes commented 2 years ago

Its a good suggestion- one reason this is not as useful as you might think is that system time is not the same as display time. If a frame takes 20ms to run, the system time could vary anywhere in that range, but everything is displayed at the same time.

Unity timing is something that is complex and I don't fully understand it- but you may have luck just recording the timestamp of when the application loads, and then adding all of your time in seconds to this value.

There is also a related time value: https://docs.unity3d.com/ScriptReference/Time-realtimeSinceStartup.html

It may be interesting to add an option to select what is displayed in the time column. The problem is that this would have to be done across trial results too, to be consistent. If you or someone else wants to develop this and submit it, I can review it. But UXF is set up that most of this can be done on a per-project basis.

JAQuent commented 2 years ago

I thought about this a bit more. Another option (at least for fMRI) is to send a trigger to the data collection computer that starts the experiment, which is easy to do in python or matlab but difficult to do in unity. As far I understand as soon as we start the unity application Time.time starts and it does not wait for a trigger (in our case it is the letter S that we use in experiments), which is currently used to time stamp.

Similar to what you suggest if I follow you correctly, I saw similar discussion for something completely unrelated in the unity forum (https://answers.unity.com/questions/728588/reset-the-timetime-back-to-00.html), which might be another option, which is creating a custom time variable called elapsed time that uses Time.time or Time.realtimeSinceStartup but where zero is not the start of the application but a specified event like when the first MRI image is taken.

I've tried to find the script that adds the time stamp in UXF but couldn't find it. If you tell me where it is I can definitely work on that.

jackbrookes commented 2 years ago

The current time (Time.time) is used in a few places in UXF: https://github.com/immersivecognition/unity-experiment-framework/search?q=Time.time

JAQuent commented 6 days ago

I never updated this post but for posterity: The easiest way is to simply record the beginning of the run (e.g. by looking for the letter S being pressed in the update function) and then use this as t = 0 in the analysis.