Просмотр исходного кода

No longer instantiate scene objects before prefab updating is done. This fixes an issue with managed game objects having different instances pointing to the same game object.

BearishSun 10 лет назад
Родитель
Сommit
a1a448e85c
3 измененных файлов с 17 добавлено и 8 удалено
  1. 7 1
      BansheeCore/Include/BsPrefab.h
  2. 9 6
      BansheeCore/Source/BsPrefab.cpp
  3. 1 1
      BansheeCore/Source/BsPrefabUtility.cpp

+ 7 - 1
BansheeCore/Include/BsPrefab.h

@@ -28,8 +28,14 @@ namespace BansheeEngine
 		 * @brief	Instantiates a prefab by creating an instance of the prefab's
 		 * @brief	Instantiates a prefab by creating an instance of the prefab's
 		 *			scene object hierarchy. The returned hierarchy will be parented
 		 *			scene object hierarchy. The returned hierarchy will be parented
 		 *			to world root by default.
 		 *			to world root by default.
+		 *			
+		 * @param	onlyClone	If true the internal prefab hierarchy will be cloned and returned, but not actually 
+		 * 						instantiated. Caller must ensure to call ::instantiate on the returned scene object. 
+		 * 						If false the returned scene object will be instantiated before returning.
+		 * 						
+		 * @returns	Clone of the prefab's scene object hierarchy.
 		 */
 		 */
-		HSceneObject instantiate();
+		HSceneObject instantiate(bool onlyClone = false);
 
 
 		/**
 		/**
 		 * @brief	Replaces the contents of this prefab with new contents
 		 * @brief	Replaces the contents of this prefab with new contents

+ 9 - 6
BansheeCore/Source/BsPrefab.cpp

@@ -87,19 +87,15 @@ namespace BansheeEngine
 		mHash++;
 		mHash++;
 	}
 	}
 
 
-	HSceneObject Prefab::instantiate()
+	HSceneObject Prefab::instantiate(bool onlyClone)
 	{
 	{
 		if (mRoot == nullptr)
 		if (mRoot == nullptr)
 			return HSceneObject();
 			return HSceneObject();
 
 
-		HSceneObject clone = mRoot->clone();
-		clone->instantiate();
-		clone->mPrefabHash = mHash;
-
 #if BS_EDITOR_BUILD
 #if BS_EDITOR_BUILD
 		// Update any child prefab instances in case their prefabs changed
 		// Update any child prefab instances in case their prefabs changed
 		Stack<HSceneObject> todo;
 		Stack<HSceneObject> todo;
-		todo.push(clone);
+		todo.push(mRoot);
 
 
 		while (!todo.empty())
 		while (!todo.empty())
 		{
 		{
@@ -119,6 +115,13 @@ namespace BansheeEngine
 		}
 		}
 #endif
 #endif
 
 
+		mRoot->mPrefabHash = mHash;
+
+		HSceneObject clone = mRoot->clone();
+
+		if (!onlyClone)
+			clone->instantiate();
+		
 		return clone;
 		return clone;
 	}
 	}
 
 

+ 1 - 1
BansheeCore/Source/BsPrefabUtility.cpp

@@ -103,7 +103,7 @@ namespace BansheeEngine
 				HSceneObject parent = current->getParent();
 				HSceneObject parent = current->getParent();
 
 
 				current->destroy(true);
 				current->destroy(true);
-				HSceneObject newInstance = prefabLink->instantiate();
+				HSceneObject newInstance = prefabLink->instantiate(true);
 
 
 				if (prefabDiff != nullptr)
 				if (prefabDiff != nullptr)
 					prefabDiff->apply(newInstance);
 					prefabDiff->apply(newInstance);