0
\$\begingroup\$

I want to lock the framerate of my scene to 30fps, then I learned from this post that fps info in Editor Stat isn't reliable, that's why my fps is still around 100. This is my script for setting the framerate (vSync also has been set into Don't Sync) :

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class TargetFramerate : MonoBehaviour {
    public int frame_rate = 30;

    void Start () {
    }

    void Awake (){
        QualitySettings.vSyncCount = 0;
        Application.targetFrameRate = frame_rate;
    }

    void Update () {
        if (frame_rate != Application.targetFrameRate) {
            Application.targetFrameRate = frame_rate;
        }
    }
}

But it doesn't work. Where should I put this script ? The description says in any GameObject will be ok, so I put in one of my GameObject with camera attached on it. By the way, I'm also using SteamVR camera script for my GameObjects (for HMD device), is it affecting this script ?

[UPDATE]

I posted the same question on Reddit, and got several feedbacks. So, the code that I used before from Wiki Unity 3D - FramePerSecond is outdated and using deprecated OnGUI system. As of now I'll try to use FPSCounter from the Standard Assets and see if it works.

Here's how it looks like on the scene using FPSCounter from Standard Assets, it works on the Game tab, but it doesn't show on the device (I'm using HMD- HTC Vive).

enter image description here

Also, my framerate lock code above doesn't seem to work, since the FPS is still reaching 90fps. Any advice ?

\$\endgroup\$
1
\$\begingroup\$

Per the documentation:

  • When using VR Unity will use the target frame rate specified by the SDK and ignore values specified by the game.
\$\endgroup\$
0
\$\begingroup\$

Add "GUI Layer" component to your main camera

\$\endgroup\$
  • \$\begingroup\$ Actually the description mentioned that there's no need of GUIText element. Anyway, I just found out that the FPS code above is outdated. I will update my question. \$\endgroup\$ – raisa_ May 21 '18 at 8:58
  • \$\begingroup\$ I said GUI Layer not Guitext \$\endgroup\$ – buffalo94 May 21 '18 at 9:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.