diff --git a/STF/Editor/Tools/STFSetup.cs b/STF/Editor/Tools/STFSetup.cs index aa9331b..5f47ace 100644 --- a/STF/Editor/Tools/STFSetup.cs +++ b/STF/Editor/Tools/STFSetup.cs @@ -107,17 +107,21 @@ public static Result FindAndSetupArmaturesInplace(GameObject Root) if(meshInstance == null) meshInstance = smr.gameObject.AddComponent(); // Check if an armatureInstance exists var armatureInstanceGo = smr.rootBone?.parent?.gameObject; - if(armatureInstanceGo == null) throw new Exception("Incorrectly setup SkinnedMeshRenderer: " + smr); - var armatureInstance = armatureInstanceGo.GetComponent(); - - // continue if an armature instance already exists. It can be assumed that its setup correctly. - if(armatureInstance != null) continue; + if(armatureInstanceGo == null) + { + Debug.LogWarning("Incorrectly setup SkinnedMeshRenderer: " + smr); + continue; + } + var armatureInstance = armatureInstanceGo.GetComponent(); if(armatureInstance == null) armatureInstance = armatureInstanceGo.AddComponent(); + // Setup armatureInstance to the definetively correct values meshInstance.ArmatureInstance = armatureInstance; armatureInstance.root = smr.rootBone?.gameObject; - armatureInstance.bones = new List(smr.bones.Select(b => b.gameObject)); + + if(smr.bones != null) armatureInstance.bones = new List(smr.bones.Select(b => b?.gameObject)); + // If the armatureInstance doesn't have an armature (eg was just created), then determine the armature from the smr bone hirarchy and the smr bind poses if(armatureInstance.armature == null && !armatureInstancesToSetup.Contains(armatureInstance)) { diff --git a/STF/Runtime/Addon/AddonApplier.cs b/STF/Runtime/Addon/AddonApplier.cs index 2ba64dd..03e9fd7 100644 --- a/STF/Runtime/Addon/AddonApplier.cs +++ b/STF/Runtime/Addon/AddonApplier.cs @@ -45,7 +45,6 @@ public static class STFAddonApplier { public static GameObject Apply(ISTFAsset Base, STFAddonAsset Addon, bool InPlace = false) { - GameObject ret = InPlace ? Base.gameObject : UnityEngine.Object.Instantiate(Base.gameObject); ret.name = Base.name + "_applied_" + Addon.Name; diff --git a/STF/Runtime/Serialisation/NodeComponents/STFTwistConstraint.cs b/STF/Runtime/Serialisation/NodeComponents/STFTwistConstraint.cs index 6d479d4..2acb35d 100644 --- a/STF/Runtime/Serialisation/NodeComponents/STFTwistConstraint.cs +++ b/STF/Runtime/Serialisation/NodeComponents/STFTwistConstraint.cs @@ -55,7 +55,7 @@ public override void ParseFromJson(ISTFAssetImportState State, JObject Json, str ParseRelationships(Json, c); c.Id = Id; c.Weight = (float)Json["weight"]; - c.Target = Json["target"] != null && State.Nodes.ContainsKey((string)Json["target"]) ? State.Nodes[(string)Json["target"]] : null; + c.Target = (string)Json["target"] != null && State.Nodes.ContainsKey((string)Json["target"]) ? State.Nodes[(string)Json["target"]] : null; c.TargetId = (string)Json["target"]; State.AddComponent(c, Id); } diff --git a/STF/Runtime/Serialisation/Resources/STFMesh.cs b/STF/Runtime/Serialisation/Resources/STFMesh.cs index f83d63c..8623c40 100644 --- a/STF/Runtime/Serialisation/Resources/STFMesh.cs +++ b/STF/Runtime/Serialisation/Resources/STFMesh.cs @@ -430,6 +430,7 @@ public void ParseFromJson(ISTFImportState State, JObject Json, string Id) mesh.SetBoneWeights(bonesPerVertexNat, weights); State.AddTask(new Task(() => { + Debug.Log(mesh.name); if(State.Resources.ContainsKey((string)Json["armature"])) { var armature = (STFArmature)State.Resources[(string)Json["armature"]]; diff --git a/STF/Runtime/Util/SerdeUtil.cs b/STF/Runtime/Util/SerdeUtil.cs index a92776c..6fee2e0 100644 --- a/STF/Runtime/Util/SerdeUtil.cs +++ b/STF/Runtime/Util/SerdeUtil.cs @@ -129,7 +129,7 @@ public static (string, JObject) SerializeNodeComponent(ISTFExportState State, Co public static string SerializeResource(ISTFExportState State, UnityEngine.Object Resource, UnityEngine.Object Context = null) { if(State.Resources.ContainsKey(Resource)) return State.Resources[Resource].Id; - if(State.Context.ResourceExporters.ContainsKey(Resource.GetType())) + else if(State.Context.ResourceExporters.ContainsKey(Resource.GetType())) { return State.Context.ResourceExporters[Resource.GetType()].SerializeToJson(State, Resource, Context); }