public int attachChildAt(Spatial child, int index) {
        if (child == null) {
            throw new IllegalArgumentException("child cannot be null");
        }
        if (child == this) {
            throw new IllegalArgumentException("Cannot add child to itself");
        }
        if (child.getParent() != this) {
            if (child.getParent() != null) {
                child.getParent().detachChild(child);
            }
            child.setParent(this);
            children.add(index, child);
            // XXX: Not entirely correct? Forces bound update up the
            // tree stemming from the attached child. Also forces
            // transform update down the tree-
            child.setTransformRefresh();
            child.setLightListRefresh();
            child.setMatParamOverrideRefresh();
            if (logger.isLoggable(Level.FINE)) {
                logger.log(Level.FINE, "Child ({0}) attached to this node ({1})",
                        new Object[]{child.getName(), getName()});
            }
            invalidateUpdateList();
        }
        return children.size();
    }
<code>attachChildAt</code> attaches a child to this node at an index. This node
becomes the child's parent. The current number of children maintained is
returned.
<br>
If the child already had a parent it is detached from that former parent.

@param child
           the child to attach to this node.
@param index
           the position where the child should be attached
@return the number of children maintained by this node.
@throws IllegalArgumentException if child is null or this
jme3-core/src/main/java/com/jme3/scene/Node.java