From a52131bf317f46b17b623b3e835e67161be7d1fd Mon Sep 17 00:00:00 2001 From: Andreas Atteneder Date: Thu, 14 Oct 2021 14:31:58 +0200 Subject: [PATCH] fix: No errors when importing empty scenes --- ChangeLog.md | 1 + Runtime/Scripts/GameObjectInstantiator.cs | 8 +++++--- Runtime/Scripts/GltfImport.cs | 13 ++++++++----- 3 files changed, 14 insertions(+), 8 deletions(-) diff --git a/ChangeLog.md b/ChangeLog.md index 1978121f..9cb0d9a2 100644 --- a/ChangeLog.md +++ b/ChangeLog.md @@ -7,6 +7,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] - ### Fixed - Corrected mesh bounds (calculated from accessor's min/max) +- No errors when importing empty scenes ## [4.3.2] - 2020-10-13 ### Added diff --git a/Runtime/Scripts/GameObjectInstantiator.cs b/Runtime/Scripts/GameObjectInstantiator.cs index aa133e8a..9b912861 100644 --- a/Runtime/Scripts/GameObjectInstantiator.cs +++ b/Runtime/Scripts/GameObjectInstantiator.cs @@ -321,9 +321,11 @@ uint[] nodeIndices var go = new GameObject(name ?? "Scene"); go.transform.SetParent( parent, false); - foreach(var nodeIndex in nodeIndices) { - if (nodes[nodeIndex] != null) { - nodes[nodeIndex].transform.SetParent( go.transform, false ); + if (nodeIndices != null) { + foreach(var nodeIndex in nodeIndices) { + if (nodes[nodeIndex] != null) { + nodes[nodeIndex].transform.SetParent( go.transform, false ); + } } } diff --git a/Runtime/Scripts/GltfImport.cs b/Runtime/Scripts/GltfImport.cs index 015eff02..69b00035 100644 --- a/Runtime/Scripts/GltfImport.cs +++ b/Runtime/Scripts/GltfImport.cs @@ -1588,13 +1588,16 @@ void PopulateHierarchy(uint nodeIndex, uint? parentIndex) { var scene = gltfRoot.scenes[sceneId]; instantiator.Init(); + + if (scene.nodes != null) { + foreach (var nodeId in scene.nodes) { + IterateNodes(nodeId,null,CreateHierarchy); + } - foreach (var nodeId in scene.nodes) { - IterateNodes(nodeId,null,CreateHierarchy); - } - foreach (var nodeId in scene.nodes) { - IterateNodes(nodeId,null,PopulateHierarchy); + foreach (var nodeId in scene.nodes) { + IterateNodes(nodeId,null,PopulateHierarchy); + } } #if UNITY_ANIMATION