Fix setting up prefab objects ids mapping for nested prefabs to link cross-object references correctly
This commit is contained in:
@@ -369,14 +369,14 @@ SceneObjectsFactory::PrefabSyncData::PrefabSyncData(Array<SceneObject*>& sceneOb
|
||||
{
|
||||
}
|
||||
|
||||
void SceneObjectsFactory::SetupPrefabInstances(Context& context, PrefabSyncData& data)
|
||||
void SceneObjectsFactory::SetupPrefabInstances(Context& context, const PrefabSyncData& data)
|
||||
{
|
||||
PROFILE_CPU_NAMED("SetupPrefabInstances");
|
||||
const int32 count = data.Data.Size();
|
||||
ASSERT(count <= data.SceneObjects.Count());
|
||||
for (int32 i = 0; i < count; i++)
|
||||
{
|
||||
SceneObject* obj = data.SceneObjects[i];
|
||||
const SceneObject* obj = data.SceneObjects[i];
|
||||
if (!obj)
|
||||
continue;
|
||||
const auto& stream = data.Data[i];
|
||||
@@ -417,6 +417,21 @@ void SceneObjectsFactory::SetupPrefabInstances(Context& context, PrefabSyncData&
|
||||
// Add to the prefab instance IDs mapping
|
||||
auto& prefabInstance = context.Instances[index];
|
||||
prefabInstance.IdsMapping[prefabObjectId] = id;
|
||||
|
||||
// Walk over nested prefabs to link any subobjects into this object (eg. if nested prefab uses cross-object references to link them correctly)
|
||||
NESTED_PREFAB_WALK:
|
||||
const ISerializable::DeserializeStream* prefabData;
|
||||
if (prefab->ObjectsDataCache.TryGet(prefabObjectId, prefabData) && JsonTools::GetGuidIfValid(prefabObjectId, *prefabData, "PrefabObjectID"))
|
||||
{
|
||||
prefabId = JsonTools::GetGuid(stream, "PrefabID");
|
||||
prefab = Content::LoadAsync<Prefab>(prefabId);
|
||||
if (prefab && !prefab->WaitForLoaded())
|
||||
{
|
||||
// Map prefab object ID to the deserialized instance ID
|
||||
prefabInstance.IdsMapping[prefabObjectId] = id;
|
||||
goto NESTED_PREFAB_WALK;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -100,7 +100,7 @@ public:
|
||||
/// </remarks>
|
||||
/// <param name="context">The serialization context.</param>
|
||||
/// <param name="data">The sync data.</param>
|
||||
static void SetupPrefabInstances(Context& context, PrefabSyncData& data);
|
||||
static void SetupPrefabInstances(Context& context, const PrefabSyncData& data);
|
||||
|
||||
/// <summary>
|
||||
/// Synchronizes the new prefab instances by spawning missing objects that were added to prefab but were not saved with scene objects collection.
|
||||
|
||||
Reference in New Issue
Block a user