Keep a certain frame within an android app

Asked

Viewed 96 times

6

I’m trying to manipulate the frame rate (frame rate) within a Unity scene, when I run it on the Unity platform, it works with the particular frame value I sent. However, when I pass it to my cell phone, it varies from 25 to 30 fps.

-> I already changed v Sync Count -> don’t use

-> I’ve changed the frame directly on Androidunityplayer.Cs

-> I’ve 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;
        }
    }
}
  • From this model I got the values I wanted inside the desktop. I also did directly in the classes that capture the scene by the Awake() function. But I was able to get the desired values by changing time settings in Unity.

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, v Sync disabled helps yes, but by default android will always run with 30 fps or at least that! So I went to project Settings and changed values related to time like: Fixed Timestep - it’s a range of frame rate that makes the calculations of the scene, as I needed something less than 20 fps, I changed this value to 0.0005 (by default it comes 0.02), I also changed the Maximum Allowed Timestep - is the maximum frame rate range that the scene can reach, when using 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 frame I needed.. I’m still new to AR and Unity programming, but I advise those who want more accurate values to work directly on the desktop.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.