- Home /
UnityEngine stability during very long runtimes
Hello, I am currently developing a Unity application where I need very high accuracy and stability from the Unity Engine during long periods of time. It would atleast need to be running for days or months, or optimally for years. It would not be impossible to restart the Unity application, but very unfortunate.
The application is supposed to be an Unity Web GL application. I need very high stability and accuracy in rotation and collision detection (OnTriggerEnter and OnTriggerExit) mostly. There will also run 2 WaitForSeconds(0.1f) calls for the whole duration and it's important this doesn't become inaccurate (meaning more than +- 0.1f).
We are not talking about my personal-made floats becoming inaccurate over a long course of time, but if there are any UnityEngine stability issues or UnityEngine floats/variables or whatever that would become inaccurate over the course of a day, month, year then this is what I am interested in.
Thanks in advance, Eirik.
Answer by Bunny83 · Jul 30, 2021 at 12:45 PM
Ohh well, where should I start here ^^. First of all a WebGL build will probably never be anything close to "stable". An application running in a JS sanbox in an emulated environment with a virtual heap, emulated garbage collection inside a garbage collected environment inside a multi page browser is prone to suffer from timing issues.
Apart from all those external influences (browser tab in the background receives way less updates and varies heavily from browser to browser), there are some things in the Unity engine that aren't designed for long running applications. Have a look at my post over here regarding floats in general but with the concrete example of Time.time.
Using coroutines and WaitForSeconds to track time will never be accurate. It highly depends on your usecase, but for long running systems you usually want to use the system time to time anything in your application.
Not sure what this has to be with phyics though. For the same reasons mentioned above, if any values get larger and larger you will run into floating point issues. However if the values stay bounded relatively close to 0 there shouldn't be much issues. Though keep in mind that the physics system is not a scientific physics system. Nvidia's PhysX is designed to be fast, not accurate. It contains many simplifications that are not physically accurate. Two examples are drag and also that it does not preserve angular momentum but just angular velocity. So certain physical effects (like the middle axis theorem) are simply not possible.
So it's actually impossible to give a clear answer to your question because we don't know what this is all about and what parts are important. Also I don't think most people have done long-time tests of the Unity engine. We as developers simply do not know how Unity or certain parts of Unity are implemented on the native side. We can only do blackbox testing and any long term effects can only be seen if you actually let it run for that long.
Though if we just talk about certain limits, beside the mentioned floating point accuracy degrading, any integer values of course are also limited to the bit size of the integer type. So for example Time.frameCount is a signed Int32. If your game runs at 60fps the frame counter is enough to count up for about 414 days, so a bit over a year. After that time the counter has to either reset or may even wrap into the negative values. Unity as so many parts that it's impossible to think of all of them.
Keep in mind that you will have issues like that on any system. Think about the GetTickCount function of the windows API. It counts the milliseconds since system start in a 32 bit unsigned integer. This will only last for about 49 days. Any system that uses the tick count to measure time or delays could fail when the counter wraps around. All integer types have some max value at which they will eventually wrap around if they are always increasing. Floating point value will never wrap around but they can saturate and either "get stuck" at a value or saturate to infinite any get stuck there instead.
Hello, thanks for an detailed explanation. I don't know why I didn't get an email or notification on the post being answered and I can't find it through the Unity Answers page. But anyway.
I wish I could describe you the whole project so it is easier to answer the question, but that is under an NDA.
Do you have any estimation on the inaccuraccy over time for WaitForSeconds and coroutines? I do use a decent amount of them (10-12, but only 2 running at all times) and it would be quite an effort to rewrite it (I have very limited time). Do they become inaccurate (more than +-0.2s) over the course of, lets say, 14 hours? It would be possible to reset the application, but it is unfortunate.
Would there be a major difference in stability of an .exe file and a webgl file? It wouldnt be impossible to use an exe file, it would just bring a workload to make it work.
Thanks for answers.
I am sorry that these questions are hard to answer.
Edit: I found this graph from this SO: https://stackoverflow.com/questions/249467/what-is-a-simple-example-of-floating-point-rounding-error . And I was wondering if I should be comparing to your table that is about float inaccuracy representing a certain number, or a sum of floats. Is time calculated from starting point to x point (aka, inaccuracy will be similar to your table) or is it based on sum$$anonymous$$g up .deltaTime or something like that (aka similar to graph shown under)?