Search Unity

Question Increasing Time.timeScale to 8 without effecting performance

Discussion in 'Scripting' started by Only4gamers, Aug 15, 2022.

  1. Only4gamers

    Only4gamers

    Joined:
    Nov 8, 2019
    Posts:
    327
    Hi there,
    I'm working on a strategy game. Where you can increase the game speed by 2, 4 and 8 times by using Time.timeScale. With 2x and 4x it works well, but with 8x it's starting to lag sometimes. I think it's normal? Right? So how can I implement 8x game speed? Is there another way?

    Side Question:
    There is one more doubt in my mind related to Time.timeScale which I read here
    https://docs.unity3d.com/ScriptReference/Time-timeScale.html
    So should I multiply Time.fixedDeltaTime by timeScale if I change timeScale? I tested the number of FixedUpdate callbacks per frame when changing timeScale, and it's already constant unrelated to timeScale.

    Code (CSharp):
    1. Time.fixedDeltaTime = this.fixedDeltaTime * Time.timeScale;
    Thanks
     
    Last edited: Aug 15, 2022
  2. PraetorBlue

    PraetorBlue

    Joined:
    Dec 13, 2012
    Posts:
    7,909
    It's not the number of FixedUpdate calls per frame that is really important for performance.
    It's the number of FixedUpdate calls per second that really matters.
     
    Only4gamers and MelvMay like this.
  3. Only4gamers

    Only4gamers

    Joined:
    Nov 8, 2019
    Posts:
    327
    Actually this is just a side question. Yes FixedUpdate calls per second is same 50 per second irrelevant of timeScale. So should I multiply Time.fixedDeltaTime by timeScale if I change timeScale? Or not? What unity doc trying to say?
     
  4. PraetorBlue

    PraetorBlue

    Joined:
    Dec 13, 2012
    Posts:
    7,909
    That's not true. If fixed timestep is 0.02 and time scale is 1, you will get 50 FixedUpdates per second. But if time scale is 2, you will get 100 FixedUpdates per second. That's why you might want to multiply time step by time scale. So you'd get back to that same 50 FixedUpdates per realtime second. This will change the fidelity of your physics simulation though.
     
    Only4gamers likes this.