Node* Node::CloneRecursive(Node* parent, SceneResolver& resolver, CreateMode mode) { // Create clone node Node* cloneNode = parent->CreateChild(0, (mode == REPLICATED && id_ < FIRST_LOCAL_ID) ? REPLICATED : LOCAL); resolver.AddNode(id_, cloneNode); // Copy attributes unsigned numAttributes = GetNumAttributes(); for (unsigned j = 0; j < numAttributes; ++j) cloneNode->SetAttribute(j, GetAttribute(j)); // Clone components for (Vector<SharedPtr<Component> >::ConstIterator i = components_.Begin(); i != components_.End(); ++i) { Component* component = *i; Component* cloneComponent = cloneNode->CreateComponent(component->GetType(), (mode == REPLICATED && component->GetID() < FIRST_LOCAL_ID) ? REPLICATED : LOCAL); if (!cloneComponent) { LOGERROR("Could not clone component " + component->GetTypeName()); continue; } resolver.AddComponent(component->GetID(), cloneComponent); numAttributes = component->GetNumAttributes(); for (unsigned j = 0; j < numAttributes; ++j) cloneComponent->SetAttribute(j, component->GetAttribute(j)); } // Clone child nodes recursively for (Vector<SharedPtr<Node> >::ConstIterator i = children_.Begin(); i != children_.End(); ++i) { Node* node = *i; node->CloneRecursive(cloneNode, resolver, mode); } return cloneNode; }