Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
10
Question by crtapps · Aug 12, 2012 at 07:07 PM · framerate

How to limit frame rate in Unity Editor

Is there any way I can limit the framerate of my game in Unity Editor?

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

4 Replies

· Add your reply
  • Sort: 
avatar image
7
Best Answer

Answer by ScroodgeM · Aug 12, 2012 at 10:24 PM

http://docs.unity3d.com/Documentation/ScriptReference/Application-targetFrameRate.html

http://docs.unity3d.com/Documentation/ScriptReference/QualitySettings-vSyncCount.html

Comment
Add comment · Show 5 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image crtapps · Aug 13, 2012 at 07:03 AM 2
Share

Thanks Scroodge, it worked for me.

the Application-targetFrameRate document said "targetFrameRate is ignored in the editor." is incorrect.

avatar image ScroodgeM · Aug 13, 2012 at 07:38 PM 0
Share

hmm 8) often used targetFrameRate in editor and just now noticed that it should not work 8)

mark answer as correct to close question

avatar image Salazar · May 11, 2014 at 09:34 AM 0
Share

This one is worked for me. $$anonymous$$y situation is , physics in editor is not same in stand alone built. So I try to find fixing the frame rate. I changed target frame rate to 60 and my problem is solved for now. I didnt test it in other devices, or frame drop situations.

avatar image GeraldOBBI · Jul 25, 2014 at 05:15 PM 1
Share

Note that this will only work when VSYNC is disabled in editor :)

avatar image almo · Dec 11, 2014 at 09:02 PM 0
Share

Application.targetFrameRate does not work for me, even with VSync off.

avatar image
29

Answer by Huacanacha · Oct 21, 2013 at 11:18 PM

There are two ways to limit the frame rate of your game. Both work in the Game view of the Unity Editor:

 void Awake () {
     QualitySettings.vSyncCount = 0;  // VSync must be disabled
     Application.targetFrameRate = 45;
 }

Or:

 void Awake () {
     // 0 for no sync, 1 for panel refresh rate, 2 for 1/2 panel rate
     QualitySettings.vSyncCount = 2;
 }

To limit the rate ONLY when playing via the Unity editor:

 void Awake () {
     #if UNITY_EDITOR
     QualitySettings.vSyncCount = 0;  // VSync must be disabled
     Application.targetFrameRate = 45;
     #endif
 }

Here is a brief explanation of each option:

Application.targetFrameRate

  • Set it to any value you desire, in frames per second. Not a guaranteed but 'best effort' depending on the hardware capabilities etc.

  • VSync must be disabled for this to work (set vSyncCount to 0)

QualitySettings.vSyncCount

  • Set it to 0,1 or 2 only... this is the number of screen/panel refreshes between each Unity frame. For a 60Hz screen 1=60fps, 2=30fps, 0=don't wait for sync.

Comment
Add comment · Show 9 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Vox Nephila · Dec 23, 2013 at 01:13 AM 1
Share

Application.targetFrameRate DOES work in the editor. I don't know where you got the information that it doesn't, but try it. I assure you it works.

avatar image Statement · Dec 23, 2013 at 01:47 AM 1
Share

@Vox Nephilia: http://docs.unity3d.com/Documentation/ScriptReference/Application-targetFrameRate.html

targetFrameRate is ignored in the editor.

Guess the docs are wrong if it works.

avatar image Vox Nephila · Dec 23, 2013 at 01:49 AM 0
Share

They're wrong then. It works for me.

avatar image Nyubis · Apr 04, 2014 at 09:36 AM 0
Share

The docs aren't exactly wrong, they're just a bit unclear. By "the editor" they don't mean the game view in the editor. They mean the editor itself. You can run your own code in the editor by using ExecuteInEdit$$anonymous$$ode, but this will ignore these framerate settings.

In the editor's game view, these settings are applied without a problem.

avatar image GeraldOBBI · Jul 25, 2014 at 05:14 PM 1
Share

For the record, in Unity 4.5.x Application.targetFrameRate works ONLY when VSync Count is set to 'Don't sync'. If VSYNC is set to any other value, the editor won't respect the value in Application.targetFrameRate

Show more comments
avatar image
2

Answer by Jaroslav-Stehlik · Jan 03, 2015 at 03:16 PM

Hello

I just wrote this frame limiter. It is straight forward. It does slowsdown your game to achieve desired framrate in editor. Use it only for testing.

 using UnityEngine;
 using System.Collections;
 using System;
 
 public class FrameLimiter : MonoBehaviour {
         
     public int desiredFPS = 60;
 
     void Awake()
     {
         Application.targetFrameRate = -1;
         QualitySettings.vSyncCount = 0;
     }
 
     void Update()
     {
         long lastTicks = DateTime.Now.Ticks;
         long currentTicks = lastTicks;
         float delay = 1f / desiredFPS;
         float elapsedTime;
 
         if (desiredFPS <= 0)
             return;
 
         while (true)
         {
             currentTicks = DateTime.Now.Ticks;
             elapsedTime = (float)TimeSpan.FromTicks(currentTicks - lastTicks).TotalSeconds;
             if(elapsedTime >= delay)
             {
                 break;
             }
         }
     }
 }
 
Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image keepthachange · Jun 13, 2016 at 07:54 PM 0
Share

After trying this out, i had to delete it cause it slowed everything down in unity and now i get a bunch of errors.

avatar image
1

Answer by mayorc1978 · Jan 12, 2014 at 01:39 PM

Actually for some reason the Application.targetFrameRate doesn't work in the GameView in the editor if you just put that in the Awake or Start Methods

But, from my tests, if you put that in Update() it works, but better executing it only once with a delay:

 using UnityEngine;
 using System.Collections;
 
 public class FrameRateManager : MonoBehaviour {
 
     public int frameRate = 60;
 
     void Start() {
         StartCoroutine(changeFramerate());
     }
     IEnumerator changeFramerate() {
         yield return new WaitForSeconds(1);
         Application.targetFrameRate = frameRate;
     }
 }
Comment
Add comment · Show 5 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Vox Nephila · Jan 12, 2014 at 03:20 PM 0
Share

I don't have to do a coroutine to do it. Works perfectly fine putting it in start for me.

avatar image mayorc1978 · Jan 13, 2014 at 09:56 AM 0
Share

Doesn't work for me without it, probably depends on hardware speed, on $$anonymous$$e it's like it gets executed faster than it gets applied, and I need to delay it to make it work.

avatar image FatWednesday · Jan 13, 2014 at 10:49 AM 0
Share

Seems I'm subbed to this thread so just as an update. I'm using unity 4.3.0f4 On the PC editor I cannot get Application.targetFrameRate to have any impact on the editor game view when testing. No matter where or how I call it.

The best chance people have if they can't get it to work will be using custom timed coroutines to control their logic. The only downside to this is that it won't set the frame rate of embedded systems such as the animation playback (which you could simulate with playback speed settings, although its not quite the same thing).

avatar image GrayedFox · Aug 27, 2014 at 01:44 PM 0
Share

@FatWednesday -- I'm using the exact same build as you (Unity Pro 4.3.0f4) and just tried: QualitySettings.vSyncCount = 2 - was a total success and allowed me to reproduce some animation issues we are having with our game on iOS.

Give it another crack, P$$anonymous$$ me or post back here if it is still not working with relevant code

avatar image CrandellWS · Aug 23, 2021 at 03:17 PM 0
Share

My high cpu went down instantly... but I never attached the script to a GameObject in any scene. I use your script only changing 60 to 30... What gives? I thought I was gonna have to attach it to something in the scene...

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

20 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Run Update at a constant framerate in a single script 3 Answers

Unity game on Android capped at 30 fps 1 Answer

Can I output at a different rate than rendering? 0 Answers

Physics behaviour changing with framerate - Is FixedUpdate() actually working properly? 3 Answers

iOS Keyboard makes performance suffer 3 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges