Search Unity

  1. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice
  2. Unity is excited to announce that we will be collaborating with TheXPlace for a summer game jam from June 13 - June 19. Learn more.
    Dismiss Notice
  3. Dismiss Notice

Editor loop why is it causing 452 ms delay?

Discussion in 'Editor & General Support' started by SunnyValleyStudio, Aug 14, 2019.

  1. SunnyValleyStudio

    SunnyValleyStudio

    Joined:
    Mar 24, 2017
    Posts:
    67
    Hi,
    I have spotted a lag issue in my game and upon investigation it appears that "Editor loop" is causing a massive delay. The delay occurs when one of the methods is called "StartBuildingPlacement()" but it appears only to have only 0.5ms delay while the Editor loop spikes in total usage intensity. The Event loop stays above 70% total usage at all times - is that good? I am new to profiling but the issue I have is that testing the game in the editor became tedious because of it. I updated the project to the latest Unity version 2019.2 but nothing has changed.
    What can I do about Event loop high time lag?

    I attach a screenshot of the profiler window.

    Thanks,
    Peter
     

    Attached Files:

  2. MartinTilo

    MartinTilo

    Unity Technologies

    Joined:
    Aug 16, 2017
    Posts:
    2,489
    Hi Peter,
    Profiling in the editor is not the most reliable way to get timings as they would occur for your game on your target platform, because the game running in Playmode is running in the same main thread as the editor around it is. This skewers timings across threads so that, e.g. the render thread has entirely different timings (i.e. it needs to render the editor; commands between main thread, render thread and GPU are send at different intervals than they would be outside the editor).

    The Profiler tries to mitigate the difference as much as it can without actually hiding time. One step taken to mitigate this was to not Profile any samples that are not originating from Playmode, i.e. the player loop but instead are attributed to the editor.
    If you want to see what the editor was doing in your case here, you'll need to turn on the 'Profile Editor' toggle in the Profiler window toolbar (or change the target from Playmode to Editor on 2019.3 and above).
    It might be that some script of yours has an effect on the editor, such as a custom inspector or similar. It might also be some AssetStore tool, or it could be an issue with the Editor itself. Profiling the editor would be the way to investigate which one it is and how to mitigate or fix this.
     
    Last edited: Aug 14, 2019
    BAZAB, Shamantiks, pako and 3 others like this.
  3. SunnyValleyStudio

    SunnyValleyStudio

    Joined:
    Mar 24, 2017
    Posts:
    67
    Thank you for a very quick answer. You're the best! I have found out an issue by an asset "NINEVA STUDIOS Project/Hierarchy Stickies". After deleting delays are gone. Thanks to the Profile Editor I have found that there is a massive amount of calls to refresh the editor.
    Thanks again!
     
    Alaadel, Shamantiks, shekalo and 3 others like this.
  4. MartinTilo

    MartinTilo

    Unity Technologies

    Joined:
    Aug 16, 2017
    Posts:
    2,489
    Nice!
    Glad it helped and happy to be able to help. You might want to let the developer of that asset and others know about this issue by posting a review on the Asset Store ;)
    Happy coding :)
     
  5. itorrri

    itorrri

    Joined:
    Feb 12, 2021
    Posts:
    2
    I don't know why but it works for me
    upload_2022-2-6_13-26-18.png
     
  6. C-C-E

    C-C-E

    Joined:
    Jan 2, 2021
    Posts:
    5
    Maybe this will help someone:

    Go to: Windows > Analysis > Profiler
    Select CPU Usage and also Switch on the top of the Profiler to "Edit Mode"
    Start the Game and press the Record Button in the Profiler. Press it again after you see some spikes appear.
    Investigate the Spikes and go down in the Hierachy of the Profiler to see the source of the high % values.

    For me it was because my Editor had more than 40 property windows (of ScriptableObjects, GameObjects etc.) opened in the Background.
    (Found in the Hierachy under: EditorLoop > Application.Tick > Application.UpdateScene > UpdateSceneIfNeeded > UpdateScene > GUIView.RepaintAll.PlayerLoopController > PropertyEditor.Paint)
    PropDraw.PNG

    So I went to: Windows > Layout > Default. And my GC Alloc went from 122k calls down to 12k (Unity 2021.3.22f1)
     
    NeptosDS, dr4, julesaintho and 2 others like this.
  7. raidofuwa

    raidofuwa

    Joined:
    Nov 26, 2018
    Posts:
    2
    itorrri's solution #5 worked for me, too.

    My Unity version is 2020.3.28f Personal on Windows 10.

    Application.targetFrameRate = 120;

    What's this??? I think this trick can't be a (at least, proper) solution for these problem, right? I think this is bug or defect of the editor...well, I'm not really sure tho.
     
  8. MartinTilo

    MartinTilo

    Unity Technologies

    Joined:
    Aug 16, 2017
    Posts:
    2,489
    I don't know. I have zero insights into itorri's or your problem. It 100% does not related to the issue of the original poster, as that was an issue with an Asset Store provided Editor extension, and neither of you posted any details on what your issues are. If you're interested in digging deeper into that, I'd be happy to look at the details. I'd ask you to please open a new thread though as this thread is getting off topic.
     
  9. unity_396465FA9C6221478176

    unity_396465FA9C6221478176

    Joined:
    Jan 13, 2024
    Posts:
    2
    got same issue, and this "random" 1 liner fixed it. I changed nothing else. Had spikes (Lags) of 0.5s, and profiler showed editor like OP.
    Code (CSharp):
    1. Application.targetFrameRate = 120;
    I might be a different issue, but same effect, I too got: "Profile Editor showed a massive amount of calls to refresh the editor."

    Update: After removing the "Application.target.." code again, it still works without lags. Might it be, that the framerate code triggers an internal Unity update/compilation that solves it somehow?
     
    Last edited: Mar 26, 2024
  10. Dist0

    Dist0

    Joined:
    Oct 28, 2017
    Posts:
    18
    Hello Martin, I have used the profile editor toggle to find out what slowing down the editor performance sometimes, and I have found an interesting observation:
    When the problem occurs It was only when one of my monobehaviour script was selected and showed in the inspector.
    With the profiler, I was able to find that there was massive unwanted binding to serializedproperties with UIElements. (the script contains many big arrays used for mesh generation)
    Those arrays has an [HideInInspector] attribute on them (so normally no binding...) but after replacing this attribute with a [System.NonSerialized], all the unwanted binding was gone, and the editor performance come back to a normal usable state :)
    Maybe could you report that to the adequate team ?
     
  11. Dist0

    Dist0

    Joined:
    Oct 28, 2017
    Posts:
    18
    I've created a simple repro project and submitted a new Bug Report with it. I'm waiting for an answer :)
     
    MartinTilo likes this.
  12. MartinTilo

    MartinTilo

    Unity Technologies

    Joined:
    Aug 16, 2017
    Posts:
    2,489
    Thanks for filing a bug report. I suspect UI TK binds everything that is serialized rather than checking the HideInInspector attribute.
     
    ThynkTekStudio likes this.
  13. Dist0

    Dist0

    Joined:
    Oct 28, 2017
    Posts:
    18
    Yeah, I was thinking something like that too ;)
    The bug report is currently in review.
     
    ThynkTekStudio and MartinTilo like this.
  14. orlando320

    orlando320

    Joined:
    Jan 6, 2022
    Posts:
    2
    Running into this issue as well but now its the editor causing this issue what going on here?


    EDIT!!

    I fixed the problem by enabling the incremental GC in the PROJECT SETTING -> PLAYER
     

    Attached Files:

    Last edited: Jun 3, 2024
    manbearpigman likes this.
  15. manbearpigman

    manbearpigman

    Joined:
    Feb 29, 2020
    Posts:
    39
    THANK YOU, it should have been on by default D:<