Skip to content
This repository was archived by the owner on May 9, 2023. It is now read-only.

Commit 365269b

Browse files
committed
Clear GameObject Component and Transform lists properly on close
1 parent 0b97339 commit 365269b

File tree

3 files changed

+19
-3
lines changed

3 files changed

+19
-3
lines changed

src/UI/Inspectors/GameObjectInspector.cs

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ public override void OnReturnToPool()
6363
addCompInput.Text = "";
6464

6565
TransformTree.Clear();
66-
ComponentList.Clear();
66+
UpdateComponents();
6767
}
6868

6969
public override void CloseInspector()
@@ -112,6 +112,9 @@ public override void Update()
112112

113113
private IEnumerable<GameObject> GetTransformEntries()
114114
{
115+
if (!GOTarget)
116+
return Enumerable.Empty<GameObject>();
117+
115118
cachedChildren.Clear();
116119
for (int i = 0; i < GOTarget.transform.childCount; i++)
117120
cachedChildren.Add(GOTarget.transform.GetChild(i).gameObject);
@@ -124,10 +127,21 @@ private IEnumerable<GameObject> GetTransformEntries()
124127
private readonly List<bool> behaviourEnabledStates = new List<bool>();
125128

126129
// ComponentList.GetRootEntriesMethod
127-
private List<Component> GetComponentEntries() => componentEntries;
130+
private List<Component> GetComponentEntries() => GOTarget ? componentEntries : Enumerable.Empty<Component>().ToList();
128131

129132
public void UpdateComponents()
130133
{
134+
if (!GOTarget)
135+
{
136+
componentEntries.Clear();
137+
compInstanceIDs.Clear();
138+
behaviourEntries.Clear();
139+
behaviourEnabledStates.Clear();
140+
ComponentList.RefreshData();
141+
ComponentList.ScrollPool.Refresh(true, true);
142+
return;
143+
}
144+
131145
// Check if we actually need to refresh the component cells or not.
132146
var comps = GOTarget.GetComponents<Component>();
133147
var behaviours = GOTarget.GetComponents<Behaviour>();

src/UI/Inspectors/GameObjectWidgets/ComponentList.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ public ComponentList(ScrollPool<ComponentCell> scrollPool, Func<List<Component>>
2121

2222
public void Clear()
2323
{
24-
this.currentEntries.Clear();
24+
RefreshData();
25+
ScrollPool.Refresh(true, true);
2526
}
2627

2728
private bool CheckShouldDisplay(Component _, string __) => true;

src/UI/Widgets/TransformTree/TransformTree.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ public void Clear()
8383
displayIndex = 0;
8484
autoExpandedIDs.Clear();
8585
expandedInstanceIDs.Clear();
86+
this.ScrollPool.Refresh(true, true);
8687
}
8788

8889
public bool IsCellExpanded(int instanceID)

0 commit comments

Comments
 (0)