- Home /
Question by
furic · Apr 16, 2015 at 10:16 AM ·
consolerealtimewarningconstructorsmain thread
How to hide "can only be called from the main thread" warning
I got a get variable as:
static public DateTime serverTime { // Make sure check obtainedServerTime before getting this
get {
if (!obtainedServerTime) return DateTime.Now;
try {
return recordedServerTime.AddSeconds (Time.realtimeSinceStartup - serverTimeShift);
} catch {
return DateTime.Now;
}
}
}
Strange enough every time I quit playing the game in Editor, the warning shown up:
get_realtimeSinceStartup can only be called from the main thread.
Constructors and field initializers will be executed from the loading thread when loading a scene.
Don't use this function in the constructor or field initializers, instead move initialization code to the Awake or Start function.
There's no effect done to the game since it only happen when quiting, but I just wanna get rid of it!
I doubted a constructor happened on quit?!? Then I commented ALL OnApplicationQuit() but the error still come out, I also try print something just before Time.realtimeSinceStartup, the text is printed but the console didn't show which function call it!!
Any idea to debug it, or a way just simple hide the error? (Try Catch not work since it's not an exception)
screen-shot-2015-04-16-at-81158-pm.png
(16.0 kB)
Comment
Your answer
![](https://koobas.hobune.stream/wayback/20220613193251im_/https://answers.unity.com/themes/thub/images/avi.jpg)