/// <summary>
        /// Adds a weapon part to the specified adaptor
        /// </summary>
        /// <param name="adaptor">the adaptor to which to add the part</param>
        /// <param name="partToAdd">the part to add</param>
        public void AddWeaponPart(Adaptor adaptor, WeaponPart partToAdd)
        {
            WeaponPart adaptorPart = FindWeaponPartRecursive(x => x.Adaptors.Contains(adaptor));

            if (adaptor == null)
            {
                return;
            }


            adaptorPart.AddChild(partToAdd);
            adaptorPart.ConnectChildToAdaptor(adaptor, partToAdd);
        }
        /// <summary>
        /// Replaces a weapon part by another of same type, trying to keep the sub-hierachy intact
        /// </summary>
        /// <param name="partToReplace">the part that will be replaced</param>
        /// <param name="replacementPart">the part that it will be replaced by</param>
        public void ReplaceWeaponPart(WeaponPart partToReplace, WeaponPart replacementPart)
        {
            if (trigger == null)
            {
                return;
            }

            //save children
            var children = new List <WeaponPart>(partToReplace.Children);

            if (partToReplace != trigger)
            {
                //save adaptor that part is connected to
                Adaptor connectingAdaptor = partToReplace.Parent.AdaptorConnections[partToReplace];
                //save parent part
                WeaponPart parent = partToReplace.Parent;


                //all children transform parent to null
                partToReplace.DetachAllChildren();

                //remove from parent
                if (partToReplace.Parent != null)
                {
                    parent.RemoveChild(partToReplace);
                }



                //add new part into hierachy

                parent.AddChild(replacementPart);
                parent.ConnectChildToAdaptor(connectingAdaptor, replacementPart);
            }
            else //is trigger aka toplevel weaponpart
            {
                replacementPart.transform.parent = partToReplace.transform.parent;
                //all children transform parent to null
                partToReplace.DetachAllChildren();
                partToReplace.transform.parent = null;
                trigger = replacementPart;
            }

            List <WeaponPart> excessParts  = new List <WeaponPart>();
            List <WeaponPart> childrenCopy = new List <WeaponPart>(children);
            int i = 0;

            //reconnect children
            foreach (Adaptor adaptor in replacementPart.Adaptors)
            {
                var child = childrenCopy.Find(x => x.PartType == adaptor.WeaponTypeOfAdaptor);
                if (child == null)
                {
                    continue;
                }

                replacementPart.AddChild(child);
                replacementPart.ConnectChildToAdaptor(adaptor, child);

                childrenCopy.Remove(child);

                i++;
            }

            excessParts = childrenCopy;

            //destroy all parts that could not be reconnected
            foreach (WeaponPart excess in excessParts)
            {
                Destroy(excess.gameObject);
            }


            //destroy the actual part
            Destroy(partToReplace.gameObject);
        }