- Home /
"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
Answer by balt · May 09, 2012 at 12:11 PM
Ok, 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).
Cheers
Balt
good answer, header: import System;
can use $$anonymous$$illiseconds ins$$anonymous$$d of tick if you have to.
Answer by Ben Ezard · Jun 11, 2012 at 10:28 AM
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 :P Hope this helps :)