UnityRuntimeInspector icon indicating copy to clipboard operation
UnityRuntimeInspector copied to clipboard

Collapse and decollapse icon still shown even though there's no child in the drawer

Open Rhitomaic opened this issue 1 year ago • 14 comments

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 image

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.

Rhitomaic avatar Jul 11 '24 03:07 Rhitomaic

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.

yasirkula avatar Jul 11 '24 14:07 yasirkula

Is there a better place for us to discuss this? I still need some help on your asset...

Rhitomaic avatar Nov 16 '24 12:11 Rhitomaic

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.

yasirkula avatar Nov 16 '24 13:11 yasirkula

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

Rhitomaic avatar Nov 17 '24 22:11 Rhitomaic

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

yasirkula avatar Nov 18 '24 07:11 yasirkula

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

Rhitomaic avatar Nov 18 '24 08:11 Rhitomaic

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?

yasirkula avatar Nov 18 '24 08:11 yasirkula

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

Rhitomaic avatar Nov 18 '24 08:11 Rhitomaic

GetChild and ChildCount are implemented by all different HierarchyData types.

yasirkula avatar Nov 18 '24 09:11 yasirkula

Will try to implement them and see if it works well then

Rhitomaic avatar Nov 18 '24 11:11 Rhitomaic

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;
	} 
}

Rhitomaic avatar Nov 18 '24 11:11 Rhitomaic

I forgot about having to access RuntimeHierarchy. Still, I think the code can be optimized further as follows: RuntimeHierarchy _hostHierarchy = Root.Hierarchy;

yasirkula avatar Nov 18 '24 14:11 yasirkula

Oh, thank you! That'll definitely improve it, should I close this issue or will you close it when you implemented a fix?

Rhitomaic avatar Nov 19 '24 00:11 Rhitomaic

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!

yasirkula avatar Nov 19 '24 06:11 yasirkula