- Home /
iPhone - Can i tell Unity to run at 60hz rather than 30hz?
I was about to try using
Application.targetFrameRate
till I realised it wasn't present in the iPhone documentation so i presume doesn't exist.
I was keen to try seeing how well my app can go on my 3GS as i'm optimising it to try and reach 30 on older devices. Running at 60hz on >= 3GS would be a nice gain, and improvement for these newer more powerful devices.
Still without that variable, i'm presuming i can't set the speed to anything different than the current ~30hz framerate, unity is using?
I've noticed that there is a kFPS #define in AppController.mm, i presume this can be used? Has anyone had any success with it? It's a bit frustrating as i'd like to scale the target fps by device type. Though i do have Unity iPhone Advanced, being a define and used in some constant variables in AppController.mm i'd presume it'd still be fiddly to expose this in any nice form. Perhaps a better option would be adding switch on device type into AppController.mm directly.. but then the patch would be vulnerable to being overwritten by Unity. Hmm.
Cheers
efge mentions below that, "Since 3.5(?) you should use Application.targetFrameRate."
Answer by Thom Denick · Jul 15, 2010 at 05:11 PM
Here's a step by step breakdown of how to revise your AppController.mm's framerate, for those not comfortable in X-Code.
- Build your project in Unity by select Build & Run from the File menu.
- Let your app launch in X-Code on your iDevice.
- Once your app has launched alt-tab to X-Code.
- On the left side of your project in X-Code, you should see a bunch of folders. Click the small arrow next to "Classes" to expand the folder.
- The second file in Classes should be "AppController.mm" this is the file you want.
- Click on the file, and the contents should display in the main panel.
- UNITY has done a fantastic job setting this file up, and all you have to do is change one constant - kFPS.
- To find kFPS Hit MacKey + F and search for 30 or kFPS. In my AppController, it is line 97.
- Change the "30.0" to "60.0" or whatever max frame rate you want.
- Save the file, and return to Unity.
- Now, once again select "Build and Run." Unity will have noticed the change and prompt you to save your build. Save in the same area (default) area, and Unity will ask if you want to Replace or Append the project there.
- Select Append, and Unity keeps your modified AppController.mm and builds a new version of your game with your new frame rate cap!
Thanks for the help Eric!
Answer by Eric5h5 · Feb 28, 2010 at 06:56 PM
Yes, changing kFPS in AppContoller.mm is how you set the framerate. If you use Append when building instead of Replace (or use Command-B for build-and-run), then AppController.mm and other changes you might have made are not overwritten.
thanks. It'd take quite a large rewrite to refactor it out into a variable that you can then override depending on what device is running it. Wouldn't know where to begin on detecting the device. I'll try and push a build out onto my 3GS and see whether it's able to hold at 60hz.
Cheers
thanks Eric5h5, how can i do this in the objectiveC of AppController.mm though? I fear its not that simple but they'll definitely be a way.