Search Unity

  1. We are migrating the Unity Forums to Unity Discussions. On July 12, the Unity Forums will become read-only. On July 15, Unity Discussions will become read-only until July 18, when the new design and the migrated forum contents will go live. Read our full announcement for more information and let us know if you have any questions.

Resolved physX fixed timestep: possible to detach fixed time from update?

Discussion in 'Physics' started by spakment, Jul 1, 2022.

  1. spakment

    spakment

    Joined:
    Dec 19, 2017
    Posts:
    96
    I'd like to allow the physics timesteps to run as fast as possible (or as slow as it needs) for a simulation, and be completely detached from the standard update loop and time.

    I'd like to set a "simulation" time increment (say 1/60th sec) and then run the physics loop as fast as possible, I don't mind if it completes in 1/6000th sec or 1 sec, just to keep running for a specified (say 10,000) steps.

    Update can be used to display the results and I don't mind if they are stuttery or janky so long as the physics loop never "bombs out" of its loop, just to keep running its loop regardless.

    Is this possible? Creative ideas welcome!

    When I try this by setting Time.fixedDeltaTime I always end up with some dropped frames and missing timesteps as the system gets saturated. I want it to always use the same timestep irrespective of how much wall time has passed and run as fast as the processor will allow.

    Edit: Does anyone have any experience of using "captureFramerate" and possibly directly setting
    fixedDeltaTime in a script that runs just before (maybe in "OnAnimatorMove"?) the physics update
     
    Last edited: Jul 1, 2022
  2. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    11,761
    There is not a separate "physics loop" off the main-thread. Unity has a main thread which runs the player-loop and this is per-frame which runs animation, physics, rendering and counts for things like fixed-update etc. It runs at whatever rate the frame-rate is. There is no "finer" loop.

    You can manually simulate physics using your own time-step: https://docs.unity3d.com/ScriptReference/Physics.Simulate.html
     
    Edy and spakment like this.
  3. spakment

    spakment

    Joined:
    Dec 19, 2017
    Posts:
    96
    Ah fabulous, I think that's exactly what I'm looking for.
    Edit: This worked perfectly.
     
    Last edited: Jul 1, 2022
    MelvMay likes this.