Skip to content

Instantly share code, notes, and snippets.

@rrazgriz
Created May 1, 2022 23:12
Show Gist options
  • Save rrazgriz/a28bb983eb4169e012340b6f1e5bf39f to your computer and use it in GitHub Desktop.
Save rrazgriz/a28bb983eb4169e012340b6f1e5bf39f to your computer and use it in GitHub Desktop.
Script to Limit framerate of unity editor, add to any GameObject to use
// Based on LLeaLoo's script
#if UNITY_EDITOR
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;
public class FramerateLimiter : MonoBehaviour
{
public int targetFrameRate = 30;
}
[CustomEditor(typeof(FramerateLimiter), true)]
public class FramerateLimiterEditor : Editor
{
private FramerateLimiter my;
public override void OnInspectorGUI()
{
my = (FramerateLimiter) target;
this.DrawDefaultInspector();
GUILayout.Label("Current Target Framerate: " + Application.targetFrameRate.ToString());
if (GUILayout.Button("Update Target")){ SetTargetFramerate(); }
}
void SetTargetFramerate()
{
my = (FramerateLimiter) target;
QualitySettings.vSyncCount = 0; // VSync must be disabled
Application.targetFrameRate = my.targetFrameRate; // Use -1 to set back to default
}
}
#endif
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment