- Home /
webgl, Unity time and system time mismatch with low FPS
Hi, I made a simple spatial memory experiment (player walk around the scene and remember the location of props. I analysed their memory error for my scientific research ) using Unity 2019.1. I built WebGL, posted on my webserver and recruited players (=experiment participants) from Mechanical Turks. The problem is that at least 15% of players experienced a laggy behaviour (low frame rate) and there is a huge mismatch between the Unity internal time and System time.
For instance, Unity.Time showed that 300 sec has passed between the events, but System.DateTime.Now indicated that 600~2000 sec has passed between the events. This problem occurred in only some players and I have no idea why or how this happened. I noticed that when this discrepancy happened, frame rate was low as 10FPS. Most other players had a decent FPS (50 or higher) and Unity Time and System Time match. I don't know what kind of system, browsers were used by players who experienced the laggy behaviour. I only have one anecdote from anonymous player that initial loading of the WebGL was fine, but the movement was very slow.
Does anyone experience a similar problem?
Why is there a discrepancy between the Unity Time and System Time? (there is no Time.scale/pause used in my game, so I think the two should be almost perfectly in line)
Is there any recommended practice/procedure that only allows users with reasonable computing facility to play the game?
any comments, help would be greatly appreciated! Thanks
Misun
Additional information about how I recorded the player's position in while loop (like below).
IEnumerator familiarPhase(){
string savefn=subId+"_familiarisation_"+System.DateTime.Now.ToString("yyyyMMdd_HHmm")+".txt";
string savetext="";
float inittime=Time.time; float timelimit=300;
while (Time.time-inittime<timelimit){
savetext=savetext+Time.time.ToString("F2")+"/t"+character.transform.position+"/n";
yield return null;
}
StartCoroutine(save2file(savefn,savetext)); //custom made function that save the string into file on the web server (using Unity SendWebrequest) }
I included System.Time information in the file name to know when the player started this part of the game. I then saved Unity internal time (Time.time). In my experiment(=game), multiple small tasks are executed in order.
Probably the most relevant looking thread is this one by @homer_3 , who experienced low FPS and mismatch in ti$$anonymous$$g when playing audio. I don't think the solution suggested to this other thread is relevant to my problem..
https://answers.unity.com/questions/1208212/time-not-accurate.html?sort=votes
System.dateTime.now is always the most accurate if I remember correctly, and Unity.time doesn't exist as far as I know, unless you mean Time.time. Of course, your issue could just be with webgl, have you tested on a standalone build?
Answer by misun1191 · Dec 16, 2020 at 06:32 AM
I now realised the reason for the mismatch between Unity Time and SystemTime in WebGL. If players defocus the WebGL browser (e.g. click other browser tab), then Unity clock is paused while System Time is still updating. So, the timing issue was independent of frame rate.
Your answer
Follow this Question
Related Questions
FPS = 440 according to Stats, but Update prints only 50 frames? 1 Answer
GameObject Instanitation causing lag on webgl for mac os with chrome 0 Answers
WebGL low fps 0 Answers
How to use CursorLockMode in webGL 0 Answers
WebGl Mouse Look Problem 0 Answers