Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Question 15fps with gizmos activated.

Discussion in 'Scripting' started by pineapuru, Mar 16, 2021.

  1. pineapuru

    pineapuru

    Joined:
    Mar 21, 2018
    Posts:
    46
    I've been away from gizmos as every time I click on the gizmo button on Unity editor, my framerate drops to 15, I never knew why, thought it may be because I had too many 'Handles' as Gizmos, so I changed them to simple Gizmos but the lag didn't stop. After using the profiler, it seems the lag comes from this:



    Can someone tell me what's really wrong? Also, even when I disable all gizmos on the gizmos tab, the lag doesn't disappear, I'm guessing Unity is considering them even with their visibility off, which is understandable. Thanks for the attention! ;)
     
  2. FlashMuller

    FlashMuller

    Joined:
    Sep 25, 2013
    Posts:
    449
    Well, you are rendering 57.646 Custom Gizmos - from what I see in the profiler. That is by any means way too much. Should there even be that many Gizmos?
     
  3. pineapuru

    pineapuru

    Joined:
    Mar 21, 2018
    Posts:
    46
    Commented out all of my Gizmos on all of the codes that had Gizmos, these below are all from Unity components. But still, I have only 15fps, when I click any object it goes to 8~5fps, I really don't know why though... I'm on Unity 2020.3, I'm sure it's not a glitch of that version as my Gizmos would explode Unity on a lot of versions I used. xD I also re-created the library folder recently, so I'm lost on what can be the reason.



    Is there any way to know what's causing this lag and this many calls without having to delete things in my project while I observe what deletion made the lag stop?
     
    Last edited: Mar 16, 2021
  4. PraetorBlue

    PraetorBlue

    Joined:
    Dec 13, 2012
    Posts:
    7,722
    I'd start experimentally disabling swathes of GameObjects in the scene and watching the profiler. Figure out which objects are causing the bulk of those calls.
     
    lordofduct likes this.
  5. pineapuru

    pineapuru

    Joined:
    Mar 21, 2018
    Posts:
    46
    Thanks, doing this I could easily find the problem, although I don't get it, the object that was lagging was mostly level decorations, because of their collision gizmos that were mesh colliders in convex mode, but even disabling the convex mode, it lags a lot, why does it lag as non-convex mesh colliders doesn't have gizmos?
     
  6. lordofduct

    lordofduct

    Joined:
    Oct 3, 2011
    Posts:
    8,380
    The allocation appears to be a 'GetComponentNullErrorWrapper'.

    This is an editor only wrapper that when you access a null object it creates this object as a way to warn you that you've accessed a destroyed/null object (we're getting into the whole unity objects can == null but not actually be null thing... not only on destroy, but also if you left them null in the inspector. Unity will actually put a dummy object there that equals null).

    This wrapper is allocated on the .net/mono side and fed to debugger to warn you about it. I bet in your Console you probably are getting 57k "null reference exceptions" appearing as well. Because it's allocated and then immediately tossed out, it's elligible for GC. And since so many were created it's causing GC to collect very frequently reducing your framerate.

    Why might this be happening is... well... without looking at your code, beyond anything I could say for sure.

    A guess though... maybe you have some static collection in your editor code that on initialize you fill with some GameObjects or Components or who knows what. But it doesn't get flushed when you change scenes or some other flush of the in scene objects purge. So they all got destroyed, but you're looping over them in your editor script calling something like GetComponent or some other unity side method on them.

    Thing is... that's just a guess.

    I like @PraetorBlue 's suggestion of just disabling swaths of gameobjects until you see that count drop. Narrowing down where the heck it's happening.

    Also, maybe show us that entire callstack all the way to the root? See what's triggering this stack down to where the alloc is happening. See if maybe we can recreate it.
     
    pineapuru likes this.
  7. pineapuru

    pineapuru

    Joined:
    Mar 21, 2018
    Posts:
    46
    I've been testing some things, I noticed that disabling my terrain (which is a isometric modular terrain, created by various and various prefabs of ground blocks) the lag stops, but these prefabs has nothing but their Mesh Renderers, I deleted collision and anything that these prefabs had before just to check (I've made a backup, don't worry). I don't see why these objects would create lag when Gizmos are activated as they're not holding any code or any collider that could have gizmos attached.

    I took some screenshots of the profiler again with some more information, although, this time I disabled everything on the scene and leaved only the terrain prefabs as I mentioned.



    I also saved the profiler data file for you guys, but the file got too big so the forum doesn't allow me to upload it, should I upload it on google drive or it doesn't help at all?

    Nothing is really appearing on my Console, should it appear though?
     
    Last edited: Mar 17, 2021
  8. pineapuru

    pineapuru

    Joined:
    Mar 21, 2018
    Posts:
    46
    Found the problem, I had a plugin to organize data and folders, I didn't think it could be the problem as it does not create in-scene gizmos, but it seems Unity may consider some editor windows gizmos too? I don't really know, although, as the plugin is really old I changed some lines of code myself and now it is not lagging anymore. ;) Thanks for the attention though.

    My recommendation for anyone who finds this looking for answers is: look through editor codes, even them not being gizmos-related.
     
  9. lordofduct

    lordofduct

    Joined:
    Oct 3, 2011
    Posts:
    8,380
    What was the plugin?
     
  10. pineapuru

    pineapuru

    Joined:
    Mar 21, 2018
    Posts:
    46
    It is called Fungus, it helps you to do a lot on your game through timelines and block chains, but it also has great features to organize data, which is what I used the most. When I remembered Fungus creates a lot of Editor windows/stuff, I searched and quickly found this: https://github.com/snozbot/fungus/pull/849

    Update: Just another quick thing, where are all of the common 'light' or 'particle' built-in icon/gizmo options? My list seems pretty short.
     
    Last edited: Mar 18, 2021