Performance issues

sythe

Member
Hey guys, let me explain the whole process.

After I installed your package I detected a major impact on my FPS in the editor, so I profiled the editor and found that this event (EditorApplication.Internal_CallHierarchyHasChanged()) is being called at every frame and is consuming big chunks of my process.

1656592490710.png

So I started to research it, at first glance it seems to be triggered when "creating, renaming, reparenting, or destroying objects in the current hierarchy, as well as loading, unloading, renaming, or reordering loaded Scenes" (according to unity docs), also in the same doc page, Unity provides a way to measure the number of objects that is being visible in the hierarchy, so I copied the code and ran 3 scenarios:

1. WIthout your controller (the event trigger just when I pause the game)

2. With your controller (in my main scene)

3. With your controller (in an empty scene)

After this, I profiled it and used the analyzer to find recurrences of this event, to check if the event is really being triggered every frame. The top data is from my scene without your controller and the bottom data is from my scene with your controller (the blank spaces in the bottom data happen when I pause the game because I'm setting the timescale to 0 then things just stop happening)
1656682114469.png


For this reason, I think that something inside your package is triggering this event every frame, so I came here to ask for help about what can I do to remove or at least reduce this bottleneck?

Any help is welcome, thanks.
 
Last edited:
I haven't heard of this happening but based on the callstack it looks like that's a Unity editor call. I am not sure why you only see it with the character controller but if you submit a bug report to Unity they should be able to look into it.
 
But why this does not happen without your controller? I mean, isn't it possible that you are triggering this (creating, renaming, reparenting, or destroying objects in the current hierarchy, as well as loading, unloading, renaming, or reordering loaded Scenes) at some point inside your package?
 
Last edited:
Objects are only created or moved when performing an action, such as firing and spawning a decal. This does look like a Unity issue though. It is related to the editor so your builds should be ok.
 
It is likely a Unity version issue. Your best route is to post the bug to Unity so they can look into it. If you are not using a LTS version I recommend using LTS as they are generally a lot more stable.
 
I'm not sure why you think that is a Unity bug, I made a new project and imported just your package, and inside your test first-person scene, this behavior keeps happening :(
I mean, the event is being called at every frame.
 
Last edited:
The character controller isn't calling that event. That's an internal Unity editor only callback so the runtime could cannot call it. It can only be fixed on the Unity side of things. Are you using an LTS version?
 
I know that this is an internal event, but you can trigger it at any point by doing some of the operations above mentioned (you can just unparent an object and this event will be triggered).

Yes, 2020 LTS
 
Good to hear that you are on LTS. The controller does set the parent of the transform, but there's no way around that. For example, when shooting a weapon, you have to reparent the decal to the hit object. There's no other way. Unity should not be causing that bottleneck because of a reparent. It's a bug in Unity. I have not noticed it before so I would also try the 2021 version to see if it's still the same issue.

The controller does not respond to the hierarchy changed event.
 
But I'm not shooting (see the third GIF), the event is being called for nothing. I don't think that this is a Unity bug, IMO the problem is the sum of your controller triggering it every time; with my scene having 120k objects. When I test with your sample scene, the event keeps happening at every frame, but you have only 5k objects to render. Let me ask one more time, is it possible that you are reparenting or renaming some inner object inside your character? I am just trying to figure out what is triggering it, cause I can't work with this significant drop in FPS.
Thank you.
 
Last edited:
When I open up a fresh copy of the demo scene in Unity 2021.3 I see the following in the profiler:

1656688663542.png

If you do a search in the code for "hierarchyChanged" you'll see that there are not any references to that callback. This is the callback that was mentioned in the docs that you linked to.

At the start the controller does reparent objects but that is only a single frame. There are no instantiations/deletions/reparentings every frame. This is why it points to a Unity issue.
 
You're debugging play mode, you have to change to editor mode, otherwise, editor operations will not appear in the profile. It isn't being triggered every frame, but it's being triggered with some frequency.


Follow the profile from a clean project
1656690794077.png
 
Last edited:
Even with 2021.3 I am not seeing the callback. By moving the camera around there isn't anything in the controller that would cause that callback to occur. If you move the character around there are surface effects which can instantiate effects but you weren't doing that in the gif. I would either try a different Unity version or submit a bug report to Unity so they can look into it.

 
Can you import your data into the analyzer and then look for this callback there? Because there you can find the whole data instead of specific frames.
 
Last edited:
I don't even see it listed in the profiler analyzer. So it again points to a Unity version specific issue.


I am signing off for the weekend - I recommend updating your Unity version to fix this. There isn't anything within the controller that would be triggering a change that often.
 
I don't think this is Unity's fault, my friend, your controller seems to be triggering it. Are you sure that you are pulling the profile data into the analyzer or are you just looking for this callback in the profile?
 
Last edited:
The file above is the profile data that you can analyze to see my results. As you can see the callback didn't appear. I recommend updating to 2021.3 as this is a Unity issue.
 
Top