Question about swapping nodes?

I have a scene I created in the scene editor. I added some custom object controls in the scene. I want to pull all of the nodes with the object control then perform a ray test to see which one is the closest to the player. In my master loop I have a storage node called collision I add the nodes to then I perform a ray test on the collision node then add the collision node back to the root node.

However doing this has caused two major issues.

1.) The geometry loses the material lighting definition after being added to the collision node. When added back to the root node the object appears as solid black.

2.) If I destroy or remove the nodes from the collision node they are by reference removed or destroyed in the rootNode.

Here is the code.

private Node                collision = new Node();

@Override
public void update(float tpf) {
      
    for (Spatial spatial : scene.node.descendantMatches(Spatial.class, null)) {

        if (spatial.getControl(ObjectControl.class) != null){
          collision.attachChild(spatial);
        }
          
    }
    // perform ray test
    rayTest(collision);
    //attach the nodes back to root node
    scene.app.getRootNode().attachChild(collision);
    
    } 

My previous method was to test each node individually with a ray test then get the node with the shortest distance. However using multiple ray cast in each loop will cause lag in large scenes so it made since to test all of the nearby objects at once.

My only solution so far is to clone the light and spatial data from the root node to the collision node then add it back to the root node. However this causes problems when the objects are added or removed from the scene at run time.

I’m sure there is a better way to do this with out cloning all of the object nodes and light nodes. Does anyone have any suggestions ?