Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Not realtime simulation without affecting FPS
#2
(21-08-2018, 11:39 AM)mmortall Wrote: Is there a way to do not-real-time simulation in the background without affecting FPS? 

I need to do a complex simulation with lots of substeps with high poly meshes and this affects fps. So I am going to show some progress bar and do simulation in the background.

Is this possible somehow? 

I need this for Cloth and Soft Body simulation.

Not unless you're willing to use threads. A simulation step cannot be chopped up in pieces. It must be run in a single go, so running it on a thread other than the main thread is the only option.

solver.SimulateStep() sends all simulation tasks to a threadpool and puts the calling thread to sleep until all tasks have been completed. You could call solver.SimulateStep() on a thread other than Unity's main thread. That would allow the main thread to continue updating stuff while this other thread waits for Obi to complete the step.

Also note that neither Obi or Unity are designed to do this. Unity expects physics simulation to be completed during FixedUpdate(), and it will not go on with the frame until FixedUpdate() has ended. So two-way interaction with rigidbodies would not work if you simulate outside of Unity's stablished update cycle. You should also keep in mind that many Unity methods/classes cannot be used outside of the main thread, so issues might arise with this.

Another, much cheaper option that might work for you is using Unity's captureFramerate: (https://docs.unity3d.com/ScriptReference...erate.html). This allows you to decouple game time from real time.
Reply


Messages In This Thread
RE: Not realtime simulation without affecting FPS - by josemendez - 21-08-2018, 12:54 PM