Keep a certain frame within an android app

6

I'm trying to manipulate the frame rate within a unity scene, when I run it on the unity platform, it works with the given frame value I gave it. However, when I switch it to my phone, it varies from 25 to 30 fps.

- > I already changed the v sync count - > do not use

- > I already changed the frame directly on AndroidUnityPlayer.cs

- > I've already used Time.captureFramerate

- > And I'm using this code to change the frame:

using UnityEngine;
using System.Collections;


public class FPSScript : MonoBehaviour {

    public float updateInterval = 0.5F;
    private float lastInterval;
    private int frames = 0;
    private float fps;

    void Start() {
        lastInterval = Time.realtimeSinceStartup;
        frames = 0;

        Application.targetFrameRate = 10;

    }

    void OnGUI() {
        GUILayout.Label("" + fps.ToString("f2"));
    }

    void Update() {
        ++frames;
        float timeNow = Time.realtimeSinceStartup;
        if (timeNow > lastInterval + updateInterval) {
            fps = frames / (timeNow - lastInterval);
            frames = 0;
            lastInterval = timeNow;
        }
    }
}
    
asked by anonymous 21.09.2015 / 01:45

1 answer

5

I would like to share the resolution of this problem, since I felt a certain lack of material helping, either in English or in Portuguese. First of all, v sync disabled yes, but by default the android will always run at 30 fps or so! So I went into project settings and changed time related values like: Fixed Timestep - it's a frame rate interval that does the scene calculations, as I needed something less than 20 fps, I changed it to 0.0005 (by default it comes to 0.02) , I have also changed the Maximum Allowed Timestep - it is the maximum frame rate range that the scene can reach, when using the Application.targetFrameRate this value is 0.33333 (ie, in most cases at least 30 fps the scene will have) I changed this value to 0.2!

No, the frame value is not accurate, but now the scene works within the time interval I needed. I'm still new to RA programming and unity, but I would advise anyone who wants more accurate values to work directly on desktop.

    
21.09.2015 / 19:18