From f825e698c9ce4c40f2926e51aebac6c147d763d7 Mon Sep 17 00:00:00 2001 From: sconel Date: Thu, 17 Jun 2021 17:37:00 -0700 Subject: [PATCH 1/2] WIP fix for referenced assets being loaded before their registration --- .../Entity/PrefabEditorEntityOwnershipService.cpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/Code/Framework/AzToolsFramework/AzToolsFramework/Entity/PrefabEditorEntityOwnershipService.cpp b/Code/Framework/AzToolsFramework/AzToolsFramework/Entity/PrefabEditorEntityOwnershipService.cpp index 336b56653b..0ddfdc8536 100644 --- a/Code/Framework/AzToolsFramework/AzToolsFramework/Entity/PrefabEditorEntityOwnershipService.cpp +++ b/Code/Framework/AzToolsFramework/AzToolsFramework/Entity/PrefabEditorEntityOwnershipService.cpp @@ -524,8 +524,6 @@ namespace AzToolsFramework rootSpawnableIndex = m_playInEditorData.m_assets.size(); } - LoadReferencedAssets(product.GetReferencedAssets()); - AZ::Data::AssetInfo info; info.m_assetId = product.GetAsset().GetId(); info.m_assetType = product.GetAssetType(); @@ -536,6 +534,11 @@ namespace AzToolsFramework m_playInEditorData.m_assets.emplace_back(product.ReleaseAsset().release(), AZ::Data::AssetLoadBehavior::Default); } + for (auto& product : context.GetProcessedObjects()) + { + LoadReferencedAssets(product.GetReferencedAssets()); + } + // make sure that PRE_NOTIFY assets get their notify before we activate, so that we can preserve the order of // (load asset) -> (notify) -> (init) -> (activate) AZ::Data::AssetManager::Instance().DispatchEvents(); From bb0c60d1d4f97dc18973dd53360f4df14b47c58b Mon Sep 17 00:00:00 2001 From: sconel Date: Fri, 18 Jun 2021 16:43:14 -0700 Subject: [PATCH 2/2] Correctly add generated spawnables to asset manager in game mode --- .../Entity/PrefabEditorEntityOwnershipService.cpp | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/Code/Framework/AzToolsFramework/AzToolsFramework/Entity/PrefabEditorEntityOwnershipService.cpp b/Code/Framework/AzToolsFramework/AzToolsFramework/Entity/PrefabEditorEntityOwnershipService.cpp index 0ddfdc8536..1172fc7162 100644 --- a/Code/Framework/AzToolsFramework/AzToolsFramework/Entity/PrefabEditorEntityOwnershipService.cpp +++ b/Code/Framework/AzToolsFramework/AzToolsFramework/Entity/PrefabEditorEntityOwnershipService.cpp @@ -532,6 +532,14 @@ namespace AzToolsFramework AZ::Data::AssetCatalogRequestBus::Broadcast( &AZ::Data::AssetCatalogRequestBus::Events::RegisterAsset, info.m_assetId, info); m_playInEditorData.m_assets.emplace_back(product.ReleaseAsset().release(), AZ::Data::AssetLoadBehavior::Default); + + // Ensure the product asset is registered with the AssetManager + // Hold on to the returned asset to keep ref count alive until we assign it the latest data + AZ::Data::Asset asset = + AZ::Data::AssetManager::Instance().FindOrCreateAsset(info.m_assetId, info.m_assetType, AZ::Data::AssetLoadBehavior::Default); + + // Update the asset registered in the AssetManager with the data of our product from the Prefab Processor + AZ::Data::AssetManager::Instance().AssignAssetData(m_playInEditorData.m_assets.back()); } for (auto& product : context.GetProcessedObjects())