Skip to content

Commit 90e7318

Browse files
authored
Merge pull request #254 from Unity-Technologies/UNI-32987-fix-null-exception-converting-missing-components
UNI-32987 fix null exception when converting to prefab with missing components
2 parents 9ef96dc + 612e601 commit 90e7318

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

Assets/FbxExporters/Editor/ConvertToModel.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -337,6 +337,11 @@ public static void CopyComponents(GameObject to, GameObject from){
337337
var originalComponents = new List<Component>(to.GetComponents<Component> ());
338338
// copy over meshes, materials, and nothing else
339339
foreach (var component in from.GetComponents<Component>()) {
340+
// ignore missing components
341+
if (component == null) {
342+
continue;
343+
}
344+
340345
var json = EditorJsonUtility.ToJson(component);
341346
if (string.IsNullOrEmpty (json)) {
342347
// this happens for missing scripts
@@ -348,6 +353,11 @@ public static void CopyComponents(GameObject to, GameObject from){
348353

349354
// Find the component to copy to.
350355
for (int i = 0, n = originalComponents.Count; i < n; i++) {
356+
// ignore missing components
357+
if (originalComponents [i] == null) {
358+
continue;
359+
}
360+
351361
if (originalComponents[i].GetType() == expectedType) {
352362
// We have found the component we are looking for,
353363
// remove it so we don't try to copy to it again

0 commit comments

Comments
 (0)