Collapse and decollapse icon still shown even though there's no child in the drawer
Description of the bug
I used the GameObjectFilter feature in RuntimeHierarchy to hide billboard objects with this script
hierarchy.GameObjectFilter += (Transform obj) => {
return obj.GetComponent<BillboardSprite>() == null;
};
But it still shows the collapse and decollapse icon
Reproduction steps
- Create a GameObject and RuntimeHierarchy
- Create a child for the GameObject
- Filter the child of the GameObject so that all of the childs in the GameObject won't be shown in the hierarchy using GameObjectFilter
- Done, collapse and decollapse icon is still shown in the RuntimeHierarchy even though all the childs are filtered
Platform specs
Please provide the following info if this is a Unity 3D repository.
- Unity version: 2021.3.33f1
- Platform: Android, Windows, Editor
- Device: Windows 11, Android 12
- How did you download the plugin: GitHub Releases
Additional info No log.
Yes this is a known issue. To avoid this issue, at each RuntimeHierarchy refresh, each Transform with children must iterate over all of their children to see if all of them are filtered out. For Transforms with lots of children, my initial assumption is that that'll take considerable amount of time. If you have any ideas, please let me know.
Is there a better place for us to discuss this? I still need some help on your asset...
If you need help about this Issue, we can continue discussing it here. For other topics, you could use this repository's Issues or Discussions.
Okay maybe let's just try to solve this issue first
I just want to try a temporary fix for now, I can't exactly locate the function where it would check how many child it should have. It will definitely lag but I can try to just refresh it whenever the scene is changed by the user
Here, you can use a combination of ChildCount and GetChild to make the necessary controls: https://github.com/yasirkula/UnityRuntimeInspector/blob/b0980bb9a554d8d429cec645593b5c207c49163a/Plugins/RuntimeInspector/Scripts/RuntimeHierarchy/HierarchyData.cs#L54
Okay that solves the issue! I just added another abstract property called FilteredChildCount, reimplement the property on all Data types and assign it to CanExpand :D
Glad to hear it! I thought ChildCount and GetChild could be used to implement this inside HierarchyData.CanExpand directly. Is there a reason you preferred creating an abstract property?
I'm not sure how to implement it, afraid to make changes to existing methods because it might break so I just play it safe for now and I'm not sure how to use GetChild when there's HierarchyDataRootSearch(?) -w-
Might want to explore an efficient solution later on, if there's anything better I can do maybe I will try it
GetChild and ChildCount are implemented by all different HierarchyData types.
Will try to implement them and see if it works well then
Reimplemented it like this
public bool CanExpand {
get {
int count = 0;
for (int i = 0; i < ChildCount; i++)
{
if (Root.Hierarchy.GameObjectFilter(GetChild(i)))
count++;
}
return count > 0;
}
}
I forgot about having to access RuntimeHierarchy. Still, I think the code can be optimized further as follows: RuntimeHierarchy _hostHierarchy = Root.Hierarchy;
Oh, thank you! That'll definitely improve it, should I close this issue or will you close it when you implemented a fix?
Happy to help. It can remain open for the time being.
PS. If you cache Root.Hierarchy outside of the for-loop, then it'd increase performance even further!