-
Notifications
You must be signed in to change notification settings - Fork 40
Tips for using LSL4Unity
In the case, you intend to stream the application/game state as an LSL stream. You got several options to sample the game state. Be aware that in any case the sampling rate might not be stable and could have a significant jitter caused by heavy game logic processed in on frame. To avoid that, split up heavy operations into smaller junks using coroutines.
Generally it makes sense to sample a unity entity like a transform or an animation at LateUpdate instead of Update. Doing so, it's more likely that you get all updates on the entity during the frame. This includes coroutines (except WaitForEndOfFrame) as well!
If you want to sample user input on a higher sampling frequence than the Update rate, use the FixedUpdate method of your Inlet implementation.
double thisMoment = liblsl.local_Clock();
provides a time stamp from a high precision clock. Use this to write multiple marker within the same moment in your code. LSLTimeSync.cs is an predefined component you could use for this requirement. Make sure, that this Script get executed before all other scripts. See the Script Execution Order documentation. The ScriptOrder Attribut took care on this!
An example snippit from the LSLMarkerStream script.
public void WriteBeforeFrameIsDisplayed(string marker)
{
StartCoroutine(WriteMarkerAfterImageIsRendered(marker));
}
IEnumerator WriteMarkerAfterImageIsRendered(string marker)
{
yield return new WaitForEndOfFrame();
Write(marker);
yield return null;
}