diff --git a/Runtime/Interaction/SnapZone.cs b/Runtime/Interaction/SnapZone.cs index d543789..095c7ed 100644 --- a/Runtime/Interaction/SnapZone.cs +++ b/Runtime/Interaction/SnapZone.cs @@ -152,24 +152,22 @@ public Mesh PreviewMesh previewMesh = value; } } - - private Material activeMaterial; - - private List validators = new List(); + private Transform initialParent; + private Material activeMaterial; private Vector3 tmpCenterOfMass; - + private List validators = new List(); + protected override void Awake() { base.Awake(); - - validators = GetComponents().ToList(); - Collider triggerCollider = gameObject.GetComponentsInChildren().FirstOrDefault(foundCollider => foundCollider.isTrigger); - if (triggerCollider == null) + validators = GetComponents().ToList(); + + if (GetComponentsInChildren()?.Any(foundCollider => foundCollider.isTrigger) == false) { - Debug.LogErrorFormat(gameObject, "The Snap Zone '{0}' does not have any trigger collider. " - + "Make sure you have at least one collider with the property `Is Trigger` enabled.", gameObject.name); + Debug.LogError($"The Snap Zone '{name}' does not have any trigger collider. " + + "Make sure you have at least one collider with the property `Is Trigger` enabled.", gameObject); } ShowHighlightObject = ShownHighlightObject != null; @@ -180,12 +178,19 @@ protected override void Awake() { UpdateHighlightMeshFilterCache(); } + + initialParent = transform.parent; + + if (initialParent != null) + { + transform.SetParent(null); + } } protected override void OnEnable() { base.OnEnable(); - + onSelectEnter.AddListener(OnAttach); onSelectExit.AddListener(OnDetach); } @@ -218,6 +223,12 @@ private void OnDrawGizmos() protected virtual void Update() { + if (initialParent != null) + { + transform.SetParent(initialParent); + initialParent = null; + } + if (socketActive && selectTarget == null) { DrawHighlightMesh();