diff --git a/Editor/WorldFixedObjectProcessor.cs b/Editor/WorldFixedObjectProcessor.cs index 7c2a9354..11030b8a 100644 --- a/Editor/WorldFixedObjectProcessor.cs +++ b/Editor/WorldFixedObjectProcessor.cs @@ -37,7 +37,7 @@ namespace nadena.dev.modular_avatar.core.editor ); var proxy = CreateProxy(); - + var parent = retargeter.CreateIntermediateObjects(proxy.gameObject); var xform = target.transform; @@ -46,6 +46,11 @@ namespace nadena.dev.modular_avatar.core.editor var oscale = xform.lossyScale; xform.localScale = new Vector3(oscale.x / pscale.x, oscale.y / pscale.y, oscale.z / pscale.z); + if (parent.transform.Find(target.gameObject.name) != null) + { + target.gameObject.name = target.gameObject.name + "$" + GUID.Generate(); + } + target.transform.SetParent(parent.transform, true); retargeter.FixupAnimations(); diff --git a/UnitTests~/WorldFixedObjectTest/WorldFixedObjectTest.cs b/UnitTests~/WorldFixedObjectTest/WorldFixedObjectTest.cs index 904c46ab..ba838bda 100644 --- a/UnitTests~/WorldFixedObjectTest/WorldFixedObjectTest.cs +++ b/UnitTests~/WorldFixedObjectTest/WorldFixedObjectTest.cs @@ -1,5 +1,6 @@ using modular_avatar_tests; using nadena.dev.modular_avatar.animation; +using nadena.dev.modular_avatar.core; using nadena.dev.modular_avatar.core.editor; using NUnit.Framework; using UnityEngine.Animations; @@ -61,4 +62,25 @@ public class WorldFixedObjectTest : TestBase Assert.That(nestedFixedObject, Is.Not.Null); Assert.That(nestedFixedObject, Is.EqualTo(nestedFixed)); } + + [Test] + public void NameCollisions() + { + var avatar = CreateRoot("Avatar"); + var target1 = CreateChild(avatar, "Target"); + var target2 = CreateChild(avatar, "Target"); + + target1.AddComponent(); + target2.AddComponent(); + + // initialize context + var buildContext = new BuildContext(avatar); + var animationServices = buildContext.PluginBuildContext.ActivateExtensionContext(); + + new WorldFixedObjectProcessor().Process(buildContext); + + Assert.AreSame(target1.transform.parent, target2.transform.parent); + Assert.AreNotSame(target1.transform.parent, avatar.transform); + Assert.AreNotSame(target1.gameObject.name, target2.gameObject.name); + } } \ No newline at end of file