Time.frameCount increasing in Editor Mode

Hello,

I have noticed that Time.frameCount value is increasing in my Editor script, whereas I am not in Play mode.
In my understanding, Time.frameCount returns the number of rendered frame, but as I am not in Play mode, I was expecting this value to stay constant. Am I wrong in my thoughts? Or in my code?

Here is my script :

// Custom Editor using SerializedProperties.
// Automatic handling of multi-object editing, undo, and prefab overrides.
[CustomEditor(typeof(ECAAnimRecorder))]
public class ECAAnimRecorderEditor : Editor {

    public SerializedProperty propStartFrame;
    public SerializedProperty propEndFrame;
    private ECAAnimRecorder ecaRecorder;
    private string m_sLabel;

    void OnEnable()
    {
        // Setup the SerializedProperties.
        propStartFrame = serializedObject.FindProperty("m_iStartingFrame");
        propEndFrame = serializedObject.FindProperty("m_iEndingFrame");
        m_sLabel = "";
    }

    public override void OnInspectorGUI () {       
        ecaRecorder = ((ECAAnimRecorder)this.target);
        // Update the serializedProperty - always do this in the beginning of OnInspectorGUI.
        serializedObject.Update();
        //can't group textfields without having an horizontal spacebar.
        EditorGUILayout.PropertyField(propStartFrame, new GUIContent("Start frame"));
        EditorGUILayout.PropertyField(propEndFrame, new GUIContent("End frame"));
        //add space before the progress bar
        EditorGUILayout.Space();
       
        ProgressBar();       
       
        // Apply changes to the serializedProperty - always do this in the end of OnInspectorGUI.
        serializedObject.ApplyModifiedProperties();
    }

    void OnDisable()
    {
        m_sLabel = "";
    }
    /// <summary>
    /// Displays a progress bar for frame recording.
    /// </summary>
    private void ProgressBar()
    {
        float fCurrentFrame = (float)Time.frameCount;
        float fStartFrame = (float)propStartFrame.intValue;
        float fEndFrame = (float)propEndFrame.intValue;
        float fTotalFrame = fEndFrame - fStartFrame;
        float fVal = fCurrentFrame / fTotalFrame;
        m_sLabel = "Recording " + fCurrentFrame.ToString() + "/" + fTotalFrame.ToString() + " frames...";
        Rect r = GUILayoutUtility.GetRect(18, 18, "TextField");
        m_sLabel = (fVal >= 1.0f) ? "Recording completed!" : m_sLabel;
        EditorGUI.ProgressBar(r, fVal, m_sLabel);       
        EditorGUILayout.Space();
    }
}

Thanks for your help.

1 Like

Old thread, but still comes up on Google, and it’s a good question. I just had this issue myself.

From what I can tell, Time.frameCount is incremented basically whenever Update occurs. In Edit Mode, I think Update occurs when you select an object in the hierarchy, when you move your mouse over the Scene window, etc. It’s not a steady 60 FPS like in Play Mode.

For most use cases, it’s probably better to not rely on frameCount in Edit Mode.