Search Unity

Instantly targetFrameRate setting from FixedUpdate()

Discussion in 'Scripting' started by weltbesterbatman, Feb 6, 2017.

  1. weltbesterbatman

    weltbesterbatman

    Joined:
    Oct 1, 2013
    Posts:
    11
    Hi,

    we develop a board game which only use UI components. Most of the time nothings happens on the screen – until the user interacts.
    To reduce battery usage, we created an idle mode with a reduced targetFrameRate of 5. After the user interacts, the targetFrameRate jumps back to 60fps to get smooth animations. Works good so far. But there is a problem with fast interactions, like dragging things. Cause of the 5 frames per second all interactions are analysed only 5 times in the second (in Update()). Considerably too long for drag actions.

    So we moved the "interaction-check-routine" in the FixedUpdate() function and get now a nearly instant feedback. The problem is that if we set targetFrameRate in FixedUpdate() the setting is ignored until the next Update() cycle. To visualize this problem:

    Current situation (simplified)

    1.00 FixedUpdate()
    1.00 Update()
    1.02 FixedUpdate()
    1.04 FixedUpdate() > user interaction: setting targetFrameRate = 60
    1.06 FixedUpdate()
    1.08 FixedUpdate()
    1.10 FixedUpdate()
    1.12 FixedUpdate()
    1.14 FixedUpdate()
    1.16 FixedUpdate()
    1.18 FixedUpdate()
    1.20 FixedUpdate()
    1.20 Update() > from now on is targetFrameRate=60 in use
    1.22 FixedUpdate()
    1.22 Update()
    1.24 FixedUpdate()
    1.24 Update()
    1.26 FixedUpdate()
    1.26 Update()


    Goal (simplified)

    1.00 FixedUpdate()
    1.00 Update()
    1.02 FixedUpdate()
    1.04 FixedUpdate() > user interaction: setting targetFrameRate = 60
    1.04 Update() > from now on is targetFrameRate=60 in use
    1.06 FixedUpdate()
    1.06 Update()
    1.08 FixedUpdate()
    1.08 Update()
    1.10 FixedUpdate()
    1.10 Update()


    I tried a lot, but I did not get it working.
    Now I hope you can help me to find a solution in something like this:

    1. Forcing an instant update cycle of the screen?
    Using BroadcastMessage() seems to start the Update() functions, but did not reset the Update cycle.
    Is it possible to manually call an "real" update cycle, like Actionscript was with updateDisplayList()?

    2. Setting something like "lastUpdateTime"?
    Is there an timer that I can set to a older time to force an earlier Update cycle?

    I would appreciate any ideas!

    Thanks

    Jan
     
    Last edited: Feb 7, 2017
  2. AndyGainey

    AndyGainey

    Joined:
    Dec 2, 2015
    Posts:
    216
    An alternative method that might give you more control is to keep the target frame rate at a normal 60 fps, but disable your camera and use its manual Render() method to force it to render only on the frames you want.
     
    Kurt-Dekker and weltbesterbatman like this.
  3. weltbesterbatman

    weltbesterbatman

    Joined:
    Oct 1, 2013
    Posts:
    11
    At the moment we don't use a camera. Our board game uses only Canvases and the Render Mode "Screen Space - Overlay". Cause it seems to be fast and stable on different devices. But thanks for the idea! It comes on the list!
     
  4. weltbesterbatman

    weltbesterbatman

    Joined:
    Oct 1, 2013
    Posts:
    11
    I mean, its a framework. Somewhere you should be able to call the Update() cycle.
    Who to ask?