Search Unity

  1. We are migrating the Unity Forums to Unity Discussions. On July 12, the Unity Forums will become read-only.

    Please, do not make any changes to your username or email addresses at during this transition time.

    It's still possible to reply to existing private message conversations during the migration, but any new replies you post will be missing after the main migration is complete. We'll do our best to migrate these messages in a follow-up step.

    On July 15, Unity Discussions will become read-only until July 18, when the new design and the migrated forum contents will go live.

    Read our full announcement for more information and let us know if you have any questions.

Feedback Editor Performance Is Unfit For VR Development

Discussion in 'Editor & General Support' started by kingofhypocrites_unity, Jul 21, 2022.

  1. kingofhypocrites_unity


    Jun 19, 2020
    I submitted a bug years ago informing Unity that having any objects selected in the Inspector upon pressing play leads to huge frame drops. For VR, this results in nausea and general discomfort. The bigger issue (perhaps) is the frustration you will often face thinking that your game is performing badly, when actually it's just the unity editor taking forever to do editor refreshes. My bug was disregarded and I was told that this is expected behavior, which is ridiculous. Expected maybe, but it's a joke honestly that it's considered acceptable. I imagine Unity doesn't do any real VR development with their own software. For those not doing VR, it's not really an issue. I can easily hit 100s of FPS in a non-VR environment despite the editor updates. On Quest and Rift however, it absolutely kills performance.

    Ultimately after spending many hours being thrown off by this issue, I realized there are a few key factors that lead to the problem.
    • Having any object visible in the Inspector upon pressing play will hurt performance.
      • Performance really gets tanked if the object selected in the inspector is getting a lot of updates (i.e.: an object is moving -- causing the transform position, etc. to get refreshed)
    • Having the hierarchy expanded will hurt performance
      • Performance really gets tanked if the hierarchy is changing often (new objects being added to the scene dynamically, etc.)
    I am able to mitigate these issues by deselecting any currently selected objects in the hierarchy and completely collapsing it before I press play. However, this can be very tedious to do every time you hit play. For those having this issue, I put together a script (credit to Peter77 for the expand code).

    Code (CSharp):
    1. using UnityEngine.SceneManagement;
    2. using UnityEngine;
    3. #if UNITY_EDITOR
    4. using UnityEditor;
    5. #endif
    7. namespace Assets.Source.Scripts.General
    8. {
    9.   public class EditorHelper : MonoBehaviour
    10.   {
    11. #if UNITY_EDITOR
    12.     public bool CollapseSceneHeirarchyOnPlay;
    13.     public bool DeselectObjectOnPlay;
    15.     private void Start()
    16.     {
    17.       if (CollapseSceneHeirarchyOnPlay)
    18.       {
    19.         Scene scene = SceneManager.GetActiveScene();
    20.         SetExpanded(scene, false);
    21.       }
    23.       if (DeselectObjectOnPlay) {
    24.         Debug.Log("unselecting");
    25.         Selection.objects = new UnityEngine.Object[0];
    26.       }
    27.     }
    29.     private static void SetExpanded(Scene scene, bool expand)
    30.     {
    31.       foreach (var window in Resources.FindObjectsOfTypeAll<SearchableEditorWindow>())
    32.       {
    33.         if (window.GetType().Name != "SceneHierarchyWindow")
    34.           continue;
    36.         var method = window.GetType().GetMethod("SetExpandedRecursive",
    37.             System.Reflection.BindingFlags.Public |
    38.             System.Reflection.BindingFlags.NonPublic |
    39.             System.Reflection.BindingFlags.Instance, null,
    40.             new[] { typeof(int), typeof(bool) }, null);
    42.         if (method == null)
    43.         {
    44.           Debug.LogError(
    45.               "Could not find method 'UnityEditor.SceneHierarchyWindow.SetExpandedRecursive(int, bool)'.");
    46.           return;
    47.         }
    49.         var field = scene.GetType().GetField("m_Handle",
    50.             System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance);
    52.         if (field == null)
    53.         {
    54.           Debug.LogError("Could not find field 'int UnityEngine.SceneManagement.Scene.m_Handle'.");
    55.           return;
    56.         }
    58.         var sceneHandle = field.GetValue(scene);
    59.         method.Invoke(window, new[] { sceneHandle, expand });
    60.       }
    61.     }
    62. #endif
    63.   }
    64. }
  2. spiney199


    Feb 11, 2021
    I mean it is expected. Each refresh of the inspector reads (and I think writes beforehand) any serialised data of the object being viewed. Any object being viewed is going to add more overhead than not viewing one. And naturally viewing an object with heavy amounts of serialised data is going to add all the more overhead. I believe the issue is more pronounced with IMGUI drawn inspectors as well.

    So I'm not sure what the expectation is here. There's always going to be overhead.

    Also why is your editor script a monobehaviour? It'd be better off as a static class decorated with [InitializeOnLoad] that subscribes to EditorApplication.playModeStageChanged. Thus you won't need to worry about putting it into an object in the scene.
  3. kingofhypocrites_unity


    Jun 19, 2020
    Yeah, I was going to comment on the fact it could be optimized to not need a gameobject. I did it that way out of laziness. Also, it has configurable options, so you would need to put in a floating window or the settings window I think.

    Expectation is just what I said. Overhead is one thing, but in VR, you can't afford a 10 fps frame drop. Imagine if your game only ran at 30 fps in the editor. Then you would understand the comparison on how detrimental the effect is in VR. The editor should be better optimized or at least more configurable to deal with this issue. You can't reasonably debug a VR game without deselecting everything.

    They might as well tell people, "You can debug with our editor, but your game will perform badly and you will experience nausea and your game will stutter and have constant performance issues, so you will be chasing your tail trying to figure out what changed, when it's just the editor."
    Last edited: Jul 21, 2022
  4. Innovine


    Aug 6, 2017
    My experience has been that its only when the transform or some other value is being updated each frame that the editor slows down. Just selecting a static object which doesn't change anything visible in the inspector seems to improve performance a lot. As does closing the Scene view entirely.

    Have to agree that it's a miserable way of doing things, but apparently that's just the way Unity is. EditorLoop takes 55-65% of my frame time. I've built a more performant in-game console using Lua which I can use for basic debugging work in a build, when I really need to do performant VR tasks.

    I am looking forward to trying other engines as soon as my current project is completed.