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

Commit 91671bf

Browse files
committed
Failsafe in case Component is null from GetComponents?
1 parent a72877b commit 91671bf

File tree

1 file changed

+26
-18
lines changed

1 file changed

+26
-18
lines changed

src/UI/Inspectors/GameObjectInspector.cs

Lines changed: 26 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -147,32 +147,39 @@ public void UpdateComponents()
147147
var behaviours = GOTarget.GetComponents<Behaviour>();
148148

149149
bool needRefresh = false;
150-
if (comps.Length != componentEntries.Count || behaviours.Length != behaviourEntries.Count)
151-
{
152-
needRefresh = true;
153-
}
154-
else
150+
151+
int count = 0;
152+
foreach (var comp in comps)
155153
{
156-
foreach (var comp in comps)
154+
if (!comp)
155+
continue;
156+
count++;
157+
if (!compInstanceIDs.Contains(comp.GetInstanceID()))
157158
{
158-
if (!compInstanceIDs.Contains(comp.GetInstanceID()))
159-
{
160-
needRefresh = true;
161-
break;
162-
}
159+
needRefresh = true;
160+
break;
163161
}
164-
165-
if (!needRefresh)
162+
}
163+
if (!needRefresh)
164+
{
165+
if (count != componentEntries.Count)
166+
needRefresh = true;
167+
else
166168
{
167-
for (int i = 0; i < behaviours.Length; i++)
169+
count = 0;
170+
foreach (var behaviour in behaviours)
168171
{
169-
var behaviour = behaviours[i];
170-
if (behaviour.enabled != behaviourEnabledStates[i])
172+
if (!behaviour)
173+
continue;
174+
if (count >= behaviourEnabledStates.Count || behaviour.enabled != behaviourEnabledStates[count])
171175
{
172176
needRefresh = true;
173177
break;
174178
}
179+
count++;
175180
}
181+
if (!needRefresh && count != behaviourEntries.Count)
182+
needRefresh = true;
176183
}
177184
}
178185

@@ -181,9 +188,9 @@ public void UpdateComponents()
181188

182189
componentEntries.Clear();
183190
compInstanceIDs.Clear();
184-
185191
foreach (var comp in comps)
186192
{
193+
if (!comp) continue;
187194
componentEntries.Add(comp);
188195
compInstanceIDs.Add(comp.GetInstanceID());
189196
}
@@ -192,6 +199,7 @@ public void UpdateComponents()
192199
behaviourEnabledStates.Clear();
193200
foreach (var behaviour in behaviours)
194201
{
202+
if (!behaviour) continue;
195203
behaviourEntries.Add(behaviour);
196204
behaviourEnabledStates.Add(behaviour.enabled);
197205
}
@@ -211,7 +219,7 @@ private void OnAddChildClicked(string input)
211219

212220
private void OnAddComponentClicked(string input)
213221
{
214-
if (ReflectionUtility.AllTypes.TryGetValue(input, out Type type))
222+
if (ReflectionUtility.GetTypeByName(input) is Type type)
215223
{
216224
try
217225
{

0 commit comments

Comments
 (0)