"get_time can only be called from the main thread"

I need to add a timestamp to some data I receive asynchronously. This means a callback is being invoked upon receipt of the data, which in turn means that’s then running in another thread. I was surprised to read earlier in these forums that Unity core itself is not thread safe, which elucidates the message I get. So, using Time.time does not work, it produces the above error.

Does anyone have any good ideas on how this could be circumvented?

Cheers
Balt

Here’s an answer I hadn’t thought of before, silly me:

Just use DateTime object instead of Time.time.

DateTime.Now.Ticks is a good number to work with
(100 nanoseconds per tick, i.e. to get seconds, divide by 1e7 /edit: this number is not constant across devices/)

Take a look at this forum post, Unity Threading Helper:
http://forum.unity3d.com/threads/90128-Unity-Threading-Helper

Are you creating the variable outside of a function with the value of Time.time?
If you want to assign the value of Time.time to a variable then you have to do it in a function
No idea why :stuck_out_tongue:
Hope this helps :slight_smile: