How to fire an event at a exact time?

I want to trigger an event at an exact time. It should be as exact as possible. Currently I do something like this:

IEnumerator FireEvent(Event e)
{
  yield return new WaitForSeconds(timer.time - e.time);
  doSomething();
}

"timer" gives me the exact gametime and e.time is the exact timestamp when my event should occur. This provides quite good results, but there is still some jitter. The events are triggered within 3-10ms of the actual timestamp. Is there a way to get even more exact triggers?

I don't think you'll get it much more accurate than this, mind you, if you have the game running at 60fps, a frame is about 16ms so for putting stuff on the screen you don't need much more accuracy I would think (physics normally runs at 50fps, 20ms). For sound, that's another story, but besides the inaccuracy of your events you'll notice buffering of audio also makes it quite tricky to have well synced audio. Not really an answer is it? If real-time really is needed I think you should consider making a plugin. Just curious, why do you need the accuracy?

What about creating your own update loop on a separate thread and putting the thread to sleep to create the desired loop time? Even still, you can't call unity functions from that thread.

Also if you did that, the changes on screen will happen NEXT frame. You simply can't make it happen any faster than the next frame.

However, from the other thread you could catch the real time at which the event did happen (at the accuracy you desire), and use the delta time between the event and the current frame time to adjust the behavior accordingly?

EDIT After rereading your post, why not simply adjust your current scheme based on the time (for instance fast forward your event to the now correct point in time)? Or is this not possible.

if you don't have physics code you can decrease the value of fixed deltaTime and run fixedUpdate in 1000 times a second and then use it to fire your events. i think unity should define something like fixedUpdate for none physics code too. using coroutines is always frame dependent because coroutines execute in each frame after all lateUpdates. using threads and plugins are possible but there you can not call unity functions. you can modify data in plugins as the texture plugin sample does but you can not call functions or ...