Topic: Webgl online mode desyncs when window is minimized
Hi guys,
I am not sure if this happens on other platforms, but in WebGL builds, online matches go out of sync if one of the players minimizes the window (or selects another tab on their browser). The reason is most browsers refresh non-selected tabs only once a second. For this reason, UFE can't send data enough times, and desync happens.
After doing some research, I found out that by adding these lines to index.htm file you can call a function in unity with an interval (like 250 milliseconds for 4 calls a second)
document.addEventListener('visibilitychange', function ()
{
if (document.visibilityState == "hidden")
{
//myGameInstance.SendMessage("Receiver", "DoSomething");
isActive = setInterval(function() { myGameInstance.SendMessage("Receiver", "DoSomething"); }, 250);
}
else
{
//myGameInstance.SendMessage("Receiver", "DoSomethingElse");
clearInterval(isActive);
isActive = false;
}
}
);
This code calls a method named DoSomething() on a gameobject called Receiver every 250 milliseconds. So kind of solves the problem. I just need to call a UFE method that sends an empty input message over the network. But unfortunately, I don't know what that method might be.
Does anybody know of a method that does that? How can I force UFE network code to send input data?
This would extremely help me and everybody else that is trying to make a UFE WebGL game.
Thanks