Browse Source

If a node is added to the scene with a zero ID (default), assign an ID. This would happen when constructing a node manually and adding it using AddChild(), instead of using CreateChild().

Lasse Öörni 12 years ago
parent
commit
f20e4968fc
1 changed files with 8 additions and 1 deletions
  1. 8 1
      Source/Engine/Scene/Scene.cpp

+ 8 - 1
Source/Engine/Scene/Scene.cpp

@@ -671,8 +671,15 @@ void Scene::NodeAdded(Node* node)
     
     node->SetScene(this);
 
-    // If we already have an existing node with the same ID, must remove the scene reference from it
+    // If the new node has an ID of zero (default), assign a replicated ID now
     unsigned id = node->GetID();
+    if (!id)
+    {
+        id = GetFreeNodeID(REPLICATED);
+        node->SetID(id);
+    }
+    
+    // If node with same ID exists, remove the scene reference from it and overwrite with the new node
     if (id < FIRST_LOCAL_ID)
     {
         HashMap<unsigned, Node*>::Iterator i = replicatedNodes_.Find(id);