Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Target framerate, vsync not functional in Linux VM

Discussion in 'Linux' started by OneManEscapePlan, May 14, 2021.

  1. OneManEscapePlan

    OneManEscapePlan

    Joined:
    Oct 14, 2015
    Posts:
    218
    I am part of a team building a special-purpose game for a customer with Unity. The game will be deployed on the customer's internal LAN to be played inside virtual machine instances running on a hypervisor server. We are perfectly aware that a VM is not an ideal platform for running a Unity game and have discussed this at length with the customer, but due to their IT infrastructure and security policies the use of a VM is non-negotiable.

    The virtual machines run CentOS 7. We've been building the game in Unity 2019.4.x (currently building from 2019.4.25f1) and are using the built-in render pipeline. We are currently testing in VMWare with hardware acceleration enabled in the VM graphics settings.

    So on to the issue: we have found that, when run our Unity game in the CentOS 7 VM, the framerate is unrestricted. Application.targetFramerate and Vsync are both completely non-functional. For example, when I play in the VM on my PC, the game runs at 500 fps, regardless of the target framerate or whether vsync is enabled. This is problematic for several reasons:
    • The engine is pushing the hardware as hard as it can, all of the time. This wastes electricity and taxes system resources on the host.
    • In a single-core environment, asynchronously loading scenes is horrendously slow because the engine is burning so much CPU time on rendering that it scarcely devotes any time to loading.
    The second issue is less important because there is the easy workaround of loading scenes synchronously, and it may turn out that the customer's VM configuration offers multiple cores (haven't gotten clarification on that point yet). The first issue is a much bigger problem; it will make the customer unhappy and may affect the performance of other VMs hosted on the same hypervisor.

    Interestingly, Application.targetFramerate and vsync both work correctly in a real CentOS 7 machine; they only fail to work in the VM. I could imagine that perhaps the virtual GPU interface doesn't support vsync, but I can't imagine why Application.targetFramerate would not work.

    Is this an engine bug? Are there any other solutions we can use?

    @Tautvydas-Zilys I've seen you discuss frame throttling in other threads and would appreciate your input if possible.
     
    Last edited: May 14, 2021
  2. Tautvydas-Zilys

    Tautvydas-Zilys

    Unity Technologies

    Joined:
    Jul 25, 2013
    Posts:
    10,646
    Application.targetFrameRate is ignored if VSync is enabled. It should work if VSync is disabled though, as it just sleeps. Did you by any chance have VSync enabled? If it's enabled and the VM actually ignores it, Unity thinks it's just a really high refresh rate display and runs as fast as it can.
     
  3. OneManEscapePlan

    OneManEscapePlan

    Joined:
    Oct 14, 2015
    Posts:
    218
    @Tautvydas-Zilys Well, I thought I tested it with vsync off, but I guess I didn't, because you're right - if vsync is off, the target framerate setting does work! Problem solved!