From 9a38bd8620cfbaa46d0b05fae92dc2664d743643 Mon Sep 17 00:00:00 2001 From: bd_ <64174065+bdunderscore@users.noreply.github.com> Date: Tue, 29 Nov 2022 09:58:12 -0800 Subject: [PATCH] Fix some issues caused by nesting AvatarDescriptors (#110) --- .../Editor/AvatarProcessor.cs | 16 ++++++++++++++++ .../Editor/MergeArmatureHook.cs | 5 +++++ 2 files changed, 21 insertions(+) diff --git a/Packages/nadena.dev.modular-avatar/Editor/AvatarProcessor.cs b/Packages/nadena.dev.modular-avatar/Editor/AvatarProcessor.cs index 8095adbe..f701b240 100644 --- a/Packages/nadena.dev.modular-avatar/Editor/AvatarProcessor.cs +++ b/Packages/nadena.dev.modular-avatar/Editor/AvatarProcessor.cs @@ -121,6 +121,22 @@ namespace nadena.dev.modular_avatar.core.editor try { + // Sometimes people like to nest one avatar in another, when transplanting clothing. To avoid issues + // with inconsistently determining the avatar root, we'll go ahead and remove the extra sub-avatars + // here. + foreach (Transform directChild in avatarGameObject.transform) + { + foreach (var component in directChild.GetComponentsInChildren(true)) + { + Object.DestroyImmediate(component); + } + + foreach (var component in directChild.GetComponentsInChildren(true)) + { + Object.DestroyImmediate(component); + } + } + new RenameParametersHook().OnPreprocessAvatar(avatarGameObject); new MenuInstallHook().OnPreprocessAvatar(avatarGameObject); new MergeArmatureHook().OnPreprocessAvatar(avatarGameObject); diff --git a/Packages/nadena.dev.modular-avatar/Editor/MergeArmatureHook.cs b/Packages/nadena.dev.modular-avatar/Editor/MergeArmatureHook.cs index 9a7c652a..035591c1 100644 --- a/Packages/nadena.dev.modular-avatar/Editor/MergeArmatureHook.cs +++ b/Packages/nadena.dev.modular-avatar/Editor/MergeArmatureHook.cs @@ -271,6 +271,11 @@ namespace nadena.dev.modular_avatar.core.editor bool zipMerge ) { + if (src == newParent) + { + throw new Exception("[ModularAvatar] Attempted to merge an armature into itself! Aborting build..."); + } + GameObject mergedSrcBone = new GameObject(src.name + "@" + GUID.Generate()); mergedSrcBone.transform.SetParent(src.transform.parent); mergedSrcBone.transform.localPosition = src.transform.localPosition;