Search Unity

Question Weird performance impact when an unused script is attached

Discussion in 'Visual Scripting' started by Marou1, Jan 4, 2023.

  1. Marou1

    Marou1

    Joined:
    Dec 13, 2021
    Posts:
    161
    Hi,

    I have a menu with different tabs.
    Selecting a tab will set active its children and set inactive the children of the other tabs.

    When no script is attached to the children, the navigation in the menu is smooth.
    When I attach a script (with many instructions) to each child, the navigation becomes slow.

    This would make sense if the instructions are actually executed, but this is not the case.
    The instructions on this script are executed only when player presses a button, otherwise nothing happens in the script.

    I even removed any trigger from the script so it cannot be executed at all.
    But just the fact that a script - never executed - is attached to the game object, it has an impact on the performances.

    And this is not related to the editor, I have the same behaviour in the build.

    Basically, it takes around 120 ms to display all the children with the script attached versus 25 ms with no script.

    I even started deleting nodes randomly from the script, and the more nodes were deleted the better were the performances, almost proportionally.

    So maybe this is an expected behaviour for you guys, but I am really surprised. For me it does not make sense.

    What do you think?

    Thanks
     
  2. PanthenEye

    PanthenEye

    Joined:
    Oct 14, 2013
    Posts:
    2,076
    Fire up the Profiler, enable deep profiling and see what eats the most performance. Hard to tell otherwise.
     
  3. Marou1

    Marou1

    Joined:
    Dec 13, 2021
    Posts:
    161
    I checked without deep profile and the only thing it tells me is that the game objects "InventorySlots" are the culprits, but I already know that. Setting them active with the script I mentioned in my first message attached creates the spike, When I remove the script the spike is not there. And instructions of the scripts are not executed.
    upload_2023-1-4_11-49-14.png

    With the deep profiling, I get this but I have no clue what it means. I see a lot of flow.invoke() and graph.instanciate(). I found tutorials on the profiler, but not on deep profiling feature.
    upload_2023-1-4_12-5-7.png
    upload_2023-1-4_12-5-23.png

    Is there some documentation to help me make sens of this?

    Thanks
     

    Attached Files:

  4. PanthenEye

    PanthenEye

    Joined:
    Oct 14, 2013
    Posts:
    2,076
    It looks like something in Update() might be setting the selected GO every frame looking at the top of the stack. Hard to tell what's going on without seeing the graphs as well.

    You could also enable Full Scripting Method Names setting per this page to get a bit clearer picture on what all of these are: https://docs.unity3d.com/Manual/ProfilerCPU.html#full-names-setting