From b04bfc459ff57c10ab21a4668c63586fcb67148a Mon Sep 17 00:00:00 2001 From: sconel Date: Mon, 10 May 2021 11:46:58 -0700 Subject: [PATCH 01/11] Asset Preload fix for json serialization and prefab game mode --- .../Registry/editorpreferences.setreg | 3 +- .../AzCore/AzCore/Asset/AssetCommon.h | 18 ++++---- .../AzCore/Asset/AssetJsonSerializer.cpp | 33 ++++++++++++- .../AzCore/Asset/AssetManagerComponent.cpp | 9 +++- .../AzCore/Serialization/SerializeContext.h | 2 - .../AzCore/AzCore/azcore_files.cmake | 2 + .../PrefabEditorEntityOwnershipService.cpp | 46 ++++++++++++++++++- .../Prefab/PrefabDomUtils.cpp | 45 ++++++++++++++++++ .../AzToolsFramework/Prefab/PrefabDomUtils.h | 11 +++++ .../Spawnable/PrefabCatchmentProcessor.cpp | 5 +- .../Prefab/Spawnable/ProcesedObjectStore.cpp | 10 ++++ .../Prefab/Spawnable/ProcesedObjectStore.h | 5 ++ .../Prefab/Spawnable/SpawnableUtils.cpp | 7 +-- .../Prefab/Spawnable/SpawnableUtils.h | 2 +- 14 files changed, 178 insertions(+), 20 deletions(-) diff --git a/AutomatedTesting/Registry/editorpreferences.setreg b/AutomatedTesting/Registry/editorpreferences.setreg index b338d6acad..d7afc9e0ae 100644 --- a/AutomatedTesting/Registry/editorpreferences.setreg +++ b/AutomatedTesting/Registry/editorpreferences.setreg @@ -1,7 +1,8 @@ { "Amazon": { "Preferences": { - "EnablePrefabSystem": false + "EnablePrefabSystem": true, + "EnablePrefabSystemWipFeatures": true } } } \ No newline at end of file diff --git a/Code/Framework/AzCore/AzCore/Asset/AssetCommon.h b/Code/Framework/AzCore/AzCore/Asset/AssetCommon.h index c8a245af68..c5cdbbf331 100644 --- a/Code/Framework/AzCore/AzCore/Asset/AssetCommon.h +++ b/Code/Framework/AzCore/AzCore/Asset/AssetCommon.h @@ -18,6 +18,7 @@ #include #include #include +#include #include #include #include @@ -216,16 +217,14 @@ namespace AZ /** * Setting for each reference (Asset) to control loading of referenced assets during serialization. */ - enum class AssetLoadBehavior : u8 - { - PreLoad = 0, ///< Serializer will "Pre load" dependencies, asset containers may load in parallel but will not signal AssetReady - QueueLoad = 1, ///< Serializer will queue an asynchronous load of the referenced asset and return the object to the user. User code should use the \ref AZ::Data::AssetBus to monitor for when it's ready. - NoLoad = 2, ///< Serializer will load reference information, but asset loading will be left to the user. User code should call Asset::QueueLoad and use the \ref AZ::Data::AssetBus to monitor for when it's ready. - ///< AssetContainers will skip NoLoad dependencies - + AZ_ENUM_WITH_UNDERLYING_TYPE(AssetLoadBehavior, u8, + (PreLoad, 0), ///< Serializer will "Pre load" dependencies, asset containers may load in parallel but will not signal AssetReady + (QueueLoad, 1), ///< Serializer will queue an asynchronous load of the referenced asset and return the object to the user. User code should use the \ref AZ::Data::AssetBus to monitor for when it's ready. + (NoLoad, 2), ///< Serializer will load reference information, but asset loading will be left to the user. User code should call Asset::QueueLoad and use the \ref AZ::Data::AssetBus to monitor for when it's ready. + ///< AssetContainers will skip NoLoad dependencies Count, - Default = QueueLoad, - }; + (Default, QueueLoad) + ); struct AssetFilterInfo { @@ -1222,6 +1221,7 @@ namespace AZ } // namespace ProductDependencyInfo } // namespace Data + AZ_TYPE_INFO_SPECIALIZE(Data::AssetLoadBehavior, "{DAF9ECED-FEF3-4D7A-A220-8CFD6A5E6DA1}"); AZ_TYPE_INFO_TEMPLATE_WITH_NAME(AZ::Data::Asset, "Asset", "{C891BF19-B60C-45E2-BFD0-027D15DDC939}", AZ_TYPE_INFO_CLASS); } // namespace AZ diff --git a/Code/Framework/AzCore/AzCore/Asset/AssetJsonSerializer.cpp b/Code/Framework/AzCore/AzCore/Asset/AssetJsonSerializer.cpp index 767dadedf8..6968b51025 100644 --- a/Code/Framework/AzCore/AzCore/Asset/AssetJsonSerializer.cpp +++ b/Code/Framework/AzCore/AzCore/Asset/AssetJsonSerializer.cpp @@ -12,6 +12,7 @@ #include #include +#include #include #include #include @@ -70,6 +71,17 @@ namespace AZ } } + { + const AZ::Data::AssetLoadBehavior autoLoadBehavior = instance->GetAutoLoadBehavior(); + const AZ::Data::AssetLoadBehavior defaultAutoLoadBehavior = defaultInstance ? + defaultInstance->GetAutoLoadBehavior() : AZ::Data::AssetLoadBehavior::Default; + + result.Combine( + ContinueStoringToJsonObjectField(outputValue, "loadBehavior", + &autoLoadBehavior, &defaultAutoLoadBehavior, + azrtti_typeid(), context)); + } + { ScopedContextPath subPathHint(context, "m_assetHint"); const AZStd::string* hint = &instance->GetHint(); @@ -100,6 +112,20 @@ namespace AZ AssetId id; JSR::ResultCode result(JSR::Tasks::ReadField); + SerializedAssetTracker** assetIdTracker = + context.GetMetadata().Find(); + + { + Data::AssetLoadBehavior loadBehavior = instance->GetAutoLoadBehavior(); + + result.Combine( + ContinueLoadingFromJsonObjectField(&loadBehavior, + azrtti_typeid(), + inputValue, "loadBehavior", context)); + + instance->SetAutoLoadBehavior(loadBehavior); + } + auto it = inputValue.FindMember("assetId"); if (it != inputValue.MemberEnd()) { @@ -107,7 +133,7 @@ namespace AZ result = ContinueLoading(&id, azrtti_typeid(), it->value, context); if (!id.m_guid.IsNull()) { - *instance = AssetManager::Instance().FindOrCreateAsset(id, instance->GetType(), AssetLoadBehavior::NoLoad); + *instance = AssetManager::Instance().FindOrCreateAsset(id, instance->GetType(), instance->GetAutoLoadBehavior()); result.Combine(context.Report(result, "Successfully created Asset with id.")); @@ -142,6 +168,11 @@ namespace AZ "The asset hint is missing for Asset, so it will be left empty.")); } + if (assetIdTracker && *assetIdTracker) + { + (*assetIdTracker)->AddAsset(*instance); + } + bool success = result.GetOutcome() <= JSR::Outcomes::PartialSkip; bool defaulted = result.GetOutcome() == JSR::Outcomes::DefaultsUsed || result.GetOutcome() == JSR::Outcomes::PartialDefaults; AZStd::string_view message = diff --git a/Code/Framework/AzCore/AzCore/Asset/AssetManagerComponent.cpp b/Code/Framework/AzCore/AzCore/Asset/AssetManagerComponent.cpp index d861614309..1075c6a931 100644 --- a/Code/Framework/AzCore/AzCore/Asset/AssetManagerComponent.cpp +++ b/Code/Framework/AzCore/AzCore/Asset/AssetManagerComponent.cpp @@ -13,7 +13,7 @@ #include #include #include -#include +#include #include #include #include @@ -24,6 +24,11 @@ namespace AZ { + namespace Data + { + AZ_ENUM_DEFINE_REFLECT_UTILITIES(AssetLoadBehavior); + } + //========================================================================= // AssetDatabaseComponent // [6/25/2012] @@ -99,6 +104,8 @@ namespace AZ if (SerializeContext* serializeContext = azrtti_cast(context)) { + AZ::Data::AssetLoadBehaviorReflect(*serializeContext); + serializeContext->RegisterGenericType>(); serializeContext->Class() diff --git a/Code/Framework/AzCore/AzCore/Serialization/SerializeContext.h b/Code/Framework/AzCore/AzCore/Serialization/SerializeContext.h index e5bc76cd19..6806232337 100644 --- a/Code/Framework/AzCore/AzCore/Serialization/SerializeContext.h +++ b/Code/Framework/AzCore/AzCore/Serialization/SerializeContext.h @@ -14,8 +14,6 @@ #include -#include - #include #include diff --git a/Code/Framework/AzCore/AzCore/azcore_files.cmake b/Code/Framework/AzCore/AzCore/azcore_files.cmake index 5357ed66a6..c6ad90200b 100644 --- a/Code/Framework/AzCore/AzCore/azcore_files.cmake +++ b/Code/Framework/AzCore/AzCore/azcore_files.cmake @@ -35,6 +35,8 @@ set(FILES Asset/AssetSerializer.h Asset/AssetTypeInfoBus.h Asset/AssetInternal/WeakAsset.h + Asset/SerializedAssetTracker.cpp + Asset/SerializedAssetTracker.h Casting/lossy_cast.h Casting/numeric_cast.h Component/Component.cpp diff --git a/Code/Framework/AzToolsFramework/AzToolsFramework/Entity/PrefabEditorEntityOwnershipService.cpp b/Code/Framework/AzToolsFramework/AzToolsFramework/Entity/PrefabEditorEntityOwnershipService.cpp index 81233069a9..a4e9d207be 100644 --- a/Code/Framework/AzToolsFramework/AzToolsFramework/Entity/PrefabEditorEntityOwnershipService.cpp +++ b/Code/Framework/AzToolsFramework/AzToolsFramework/Entity/PrefabEditorEntityOwnershipService.cpp @@ -13,6 +13,7 @@ #include #include #include +#include #include #include #include @@ -342,6 +343,45 @@ namespace AzToolsFramework m_validateEntitiesCallback = AZStd::move(validateEntitiesCallback); } + void LoadReferencedAssets(AZStd::vector>& referencedAssets) + { + for (AZ::Data::Asset& asset : referencedAssets) + { + if (!asset.GetId().IsValid()) + { + continue; + } + + const AZ::Data::AssetLoadBehavior loadBehavior = asset.GetAutoLoadBehavior(); + + if (loadBehavior == AZ::Data::AssetLoadBehavior::NoLoad) + { + continue; + } + + AZ::Data::AssetId assetId = asset.GetId(); + AZ::Data::AssetType assetType = asset.GetType(); + const bool blockingLoad = loadBehavior == AZ::Data::AssetLoadBehavior::PreLoad; + + asset = AZ::Data::AssetManager::Instance().GetAsset(assetId, assetType, loadBehavior); + + if (!asset.GetId().IsValid()) + { + continue; + } + + if (blockingLoad) + { + asset.BlockUntilLoadComplete(); + + if (asset.IsError()) + { + continue; + } + } + } + } + void PrefabEditorEntityOwnershipService::StartPlayInEditor() { // This is a workaround until the replacement for GameEntityContext is done @@ -381,13 +421,15 @@ 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(); info.m_relativePath = product.GetId(); AZ::Data::AssetCatalogRequestBus::Broadcast( - &AZ::Data::AssetCatalogRequestBus::Events::RegisterAsset, product.GetAsset().GetId(), info); + &AZ::Data::AssetCatalogRequestBus::Events::RegisterAsset, info.m_assetId, info); m_playInEditorData.m_assets.emplace_back(product.ReleaseAsset().release(), AZ::Data::AssetLoadBehavior::Default); } @@ -398,6 +440,8 @@ namespace AzToolsFramework m_playInEditorData.m_entities.SpawnAllEntities(); } + AZ::Data::AssetManager::Instance().DispatchEvents(); + // This is a workaround until the replacement for GameEntityContext is done AzFramework::GameEntityContextEventBus::Broadcast( &AzFramework::GameEntityContextEventBus::Events::OnGameEntitiesStarted); diff --git a/Code/Framework/AzToolsFramework/AzToolsFramework/Prefab/PrefabDomUtils.cpp b/Code/Framework/AzToolsFramework/AzToolsFramework/Prefab/PrefabDomUtils.cpp index d53aeaa241..ae1737f907 100644 --- a/Code/Framework/AzToolsFramework/AzToolsFramework/Prefab/PrefabDomUtils.cpp +++ b/Code/Framework/AzToolsFramework/AzToolsFramework/Prefab/PrefabDomUtils.cpp @@ -11,8 +11,10 @@ */ #include +#include #include #include + #include #include #include @@ -115,6 +117,49 @@ namespace AzToolsFramework return true; } + bool LoadInstanceFromPrefabDom( + Instance& instance, const PrefabDom& prefabDom, AZStd::vector>& loadedAssets, LoadInstanceFlags flags) + { + // When entities are rebuilt they are first destroyed. As a result any assets they were exclusively holding on to will + // be released and reloaded once the entities are built up again. By suspending asset release temporarily the asset reload + // is avoided. + AZ::Data::AssetManager::Instance().SuspendAssetRelease(); + + InstanceEntityIdMapper entityIdMapper; + entityIdMapper.SetLoadingInstance(instance); + if ((flags & LoadInstanceFlags::AssignRandomEntityId) == LoadInstanceFlags::AssignRandomEntityId) + { + entityIdMapper.SetEntityIdGenerationApproach(InstanceEntityIdMapper::EntityIdGenerationApproach::Random); + } + + AZ::Data::SerializedAssetTracker assetTracker; + + AZ::JsonDeserializerSettings settings; + // The InstanceEntityIdMapper is registered twice because it's used in several places during deserialization where one is + // specific for the InstanceEntityIdMapper and once for the generic JsonEntityIdMapper. Because the Json Serializer's meta + // data has strict typing and doesn't look for inheritance both have to be explicitly added so they're found both locations. + settings.m_metadata.Add(static_cast(&entityIdMapper)); + settings.m_metadata.Add(&entityIdMapper); + settings.m_metadata.Add(&assetTracker); + + AZ::JsonSerializationResult::ResultCode result = + AZ::JsonSerialization::Load(instance, prefabDom, settings); + + AZ::Data::AssetManager::Instance().ResumeAssetRelease(); + + if (result.GetProcessing() == AZ::JsonSerializationResult::Processing::Halted) + { + AZ_Error("Prefab", false, + "Failed to de-serialize Prefab Instance from Prefab DOM. " + "Unable to proceed."); + + return false; + } + + loadedAssets = assetTracker.GetTrackedAssets(); + return true; + } + bool LoadInstanceFromPrefabDom( Instance& instance, Instance::EntityList& newlyAddedEntities, const PrefabDom& prefabDom, LoadInstanceFlags flags) { diff --git a/Code/Framework/AzToolsFramework/AzToolsFramework/Prefab/PrefabDomUtils.h b/Code/Framework/AzToolsFramework/AzToolsFramework/Prefab/PrefabDomUtils.h index c4b988e36f..1f000c2f70 100644 --- a/Code/Framework/AzToolsFramework/AzToolsFramework/Prefab/PrefabDomUtils.h +++ b/Code/Framework/AzToolsFramework/AzToolsFramework/Prefab/PrefabDomUtils.h @@ -13,6 +13,7 @@ #pragma once #include +#include #include #include @@ -67,6 +68,16 @@ namespace AzToolsFramework bool LoadInstanceFromPrefabDom( Instance& instance, const PrefabDom& prefabDom, LoadInstanceFlags flags = LoadInstanceFlags::None); + /** + * Loads a valid Prefab Instance from a Prefab Dom. Useful for generating Instances. + * @param instance The Instance to load. + * @param prefabDom the prefabDom that will be used to load the Instance data. + * @param shouldClearContainers whether to clear containers in Instance while loading. + * @return bool on whether the operation succeeded. + */ + bool LoadInstanceFromPrefabDom( + Instance& instance, const PrefabDom& prefabDom, AZStd::vector>& loadedAssets, LoadInstanceFlags flags = LoadInstanceFlags::None); + /** * Loads a valid Prefab Instance from a Prefab Dom. Useful for generating Instances. * @param instance The Instance to load. diff --git a/Code/Framework/AzToolsFramework/AzToolsFramework/Prefab/Spawnable/PrefabCatchmentProcessor.cpp b/Code/Framework/AzToolsFramework/AzToolsFramework/Prefab/Spawnable/PrefabCatchmentProcessor.cpp index 5d8f1f35e3..9ae795dbf1 100644 --- a/Code/Framework/AzToolsFramework/AzToolsFramework/Prefab/Spawnable/PrefabCatchmentProcessor.cpp +++ b/Code/Framework/AzToolsFramework/AzToolsFramework/Prefab/Spawnable/PrefabCatchmentProcessor.cpp @@ -20,6 +20,8 @@ #include #include +#include + namespace AzToolsFramework::Prefab::PrefabConversionUtils { void PrefabCatchmentProcessor::Process(PrefabProcessorContext& context) @@ -63,7 +65,8 @@ namespace AzToolsFramework::Prefab::PrefabConversionUtils AZStd::move(uniqueName), context.GetSourceUuid(), AZStd::move(serializer)); AZ_Assert(spawnable, "Failed to create a new spawnable."); - bool result = SpawnableUtils::CreateSpawnable(*spawnable, prefab); + Prefab::PrefabDomUtils::PrintPrefabDomValue("Prefab used for spawnable", prefab); + bool result = SpawnableUtils::CreateSpawnable(*spawnable, prefab, object.GetReferencedAssets()); if (result) { AzFramework::Spawnable::EntityList& entities = spawnable->GetEntities(); diff --git a/Code/Framework/AzToolsFramework/AzToolsFramework/Prefab/Spawnable/ProcesedObjectStore.cpp b/Code/Framework/AzToolsFramework/AzToolsFramework/Prefab/Spawnable/ProcesedObjectStore.cpp index ee45c258ff..78d1332a71 100644 --- a/Code/Framework/AzToolsFramework/AzToolsFramework/Prefab/Spawnable/ProcesedObjectStore.cpp +++ b/Code/Framework/AzToolsFramework/AzToolsFramework/Prefab/Spawnable/ProcesedObjectStore.cpp @@ -56,6 +56,16 @@ namespace AzToolsFramework::Prefab::PrefabConversionUtils return *m_asset; } + AZStd::vector>& ProcessedObjectStore::GetReferencedAssets() + { + return m_referencedAssets; + } + + const AZStd::vector>& ProcessedObjectStore::GetReferencedAssets() const + { + return m_referencedAssets; + } + AZStd::unique_ptr ProcessedObjectStore::ReleaseAsset() { return AZStd::move(m_asset); diff --git a/Code/Framework/AzToolsFramework/AzToolsFramework/Prefab/Spawnable/ProcesedObjectStore.h b/Code/Framework/AzToolsFramework/AzToolsFramework/Prefab/Spawnable/ProcesedObjectStore.h index a24d1f24c5..48e0007516 100644 --- a/Code/Framework/AzToolsFramework/AzToolsFramework/Prefab/Spawnable/ProcesedObjectStore.h +++ b/Code/Framework/AzToolsFramework/AzToolsFramework/Prefab/Spawnable/ProcesedObjectStore.h @@ -48,6 +48,10 @@ namespace AzToolsFramework::Prefab::PrefabConversionUtils AZ::Data::AssetData& GetAsset(); AZStd::unique_ptr ReleaseAsset(); + AZStd::vector>& GetReferencedAssets(); + const AZStd::vector>& GetReferencedAssets() const; + + const AZStd::string& GetId() const; private: @@ -55,6 +59,7 @@ namespace AzToolsFramework::Prefab::PrefabConversionUtils SerializerFunction m_assetSerializer; AZStd::unique_ptr m_asset; + AZStd::vector> m_referencedAssets; AZStd::string m_uniqueId; }; diff --git a/Code/Framework/AzToolsFramework/AzToolsFramework/Prefab/Spawnable/SpawnableUtils.cpp b/Code/Framework/AzToolsFramework/AzToolsFramework/Prefab/Spawnable/SpawnableUtils.cpp index 713a5d8205..085758cda9 100644 --- a/Code/Framework/AzToolsFramework/AzToolsFramework/Prefab/Spawnable/SpawnableUtils.cpp +++ b/Code/Framework/AzToolsFramework/AzToolsFramework/Prefab/Spawnable/SpawnableUtils.cpp @@ -28,16 +28,17 @@ namespace AzToolsFramework::Prefab::SpawnableUtils AzFramework::Spawnable CreateSpawnable(const PrefabDom& prefabDom) { AzFramework::Spawnable spawnable; - [[maybe_unused]] bool result = CreateSpawnable(spawnable, prefabDom); + AZStd::vector> referencedAssets; + [[maybe_unused]] bool result = CreateSpawnable(spawnable, prefabDom, referencedAssets); AZ_Assert(result, "Failed to Load Prefab Instance from given Prefab DOM while Spawnable creation."); return spawnable; } - bool CreateSpawnable(AzFramework::Spawnable& spawnable, const PrefabDom& prefabDom) + bool CreateSpawnable(AzFramework::Spawnable& spawnable, const PrefabDom& prefabDom, AZStd::vector>& referencedAssets) { Instance instance; - if (Prefab::PrefabDomUtils::LoadInstanceFromPrefabDom(instance, prefabDom, + if (Prefab::PrefabDomUtils::LoadInstanceFromPrefabDom(instance, prefabDom, referencedAssets, Prefab::PrefabDomUtils::LoadInstanceFlags::AssignRandomEntityId)) // Always assign random entity ids because the spawnable is // going to be used to create clones of the entities. { diff --git a/Code/Framework/AzToolsFramework/AzToolsFramework/Prefab/Spawnable/SpawnableUtils.h b/Code/Framework/AzToolsFramework/AzToolsFramework/Prefab/Spawnable/SpawnableUtils.h index 74cbbcb1e4..c30e5ea77a 100644 --- a/Code/Framework/AzToolsFramework/AzToolsFramework/Prefab/Spawnable/SpawnableUtils.h +++ b/Code/Framework/AzToolsFramework/AzToolsFramework/Prefab/Spawnable/SpawnableUtils.h @@ -18,7 +18,7 @@ namespace AzToolsFramework::Prefab::SpawnableUtils { AzFramework::Spawnable CreateSpawnable(const PrefabDom& prefabDom); - bool CreateSpawnable(AzFramework::Spawnable& spawnable, const PrefabDom& prefabDom); + bool CreateSpawnable(AzFramework::Spawnable& spawnable, const PrefabDom& prefabDom, AZStd::vector>& referencedAssets); void SortEntitiesByTransformHierarchy(AzFramework::Spawnable& spawnable); } // namespace AzToolsFramework::Prefab::SpawnableUtils From 2e9ae76596c87ff5b3f7d2b62a4892922090a2ca Mon Sep 17 00:00:00 2001 From: sconel Date: Mon, 10 May 2021 12:11:53 -0700 Subject: [PATCH 02/11] Removed print statement, adding in new files that were missed --- .../Registry/editorpreferences.setreg | 3 +- .../AzCore/Asset/SerializedAssetTracker.cpp | 29 ++++++++++++++++ .../AzCore/Asset/SerializedAssetTracker.h | 33 +++++++++++++++++++ .../Prefab/PrefabDomUtils.cpp | 4 +-- .../AzToolsFramework/Prefab/PrefabDomUtils.h | 3 +- .../Spawnable/PrefabCatchmentProcessor.cpp | 3 -- 6 files changed, 67 insertions(+), 8 deletions(-) create mode 100644 Code/Framework/AzCore/AzCore/Asset/SerializedAssetTracker.cpp create mode 100644 Code/Framework/AzCore/AzCore/Asset/SerializedAssetTracker.h diff --git a/AutomatedTesting/Registry/editorpreferences.setreg b/AutomatedTesting/Registry/editorpreferences.setreg index d7afc9e0ae..b338d6acad 100644 --- a/AutomatedTesting/Registry/editorpreferences.setreg +++ b/AutomatedTesting/Registry/editorpreferences.setreg @@ -1,8 +1,7 @@ { "Amazon": { "Preferences": { - "EnablePrefabSystem": true, - "EnablePrefabSystemWipFeatures": true + "EnablePrefabSystem": false } } } \ No newline at end of file diff --git a/Code/Framework/AzCore/AzCore/Asset/SerializedAssetTracker.cpp b/Code/Framework/AzCore/AzCore/Asset/SerializedAssetTracker.cpp new file mode 100644 index 0000000000..b3fad2431f --- /dev/null +++ b/Code/Framework/AzCore/AzCore/Asset/SerializedAssetTracker.cpp @@ -0,0 +1,29 @@ +/* +* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or +* its licensors. +* +* For complete copyright and license terms please see the LICENSE at the root of this +* distribution (the "License"). All use of this software is governed by the License, +* or, if provided, by the license below or the license accompanying this file. Do not +* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* +*/ + +#include + +namespace AZ +{ + namespace Data + { + void SerializedAssetTracker::AddAsset(Asset& asset) + { + m_serializedAssets.emplace_back(asset); + } + + const AZStd::vector>& SerializedAssetTracker::GetTrackedAssets() const + { + return m_serializedAssets; + } + } +} diff --git a/Code/Framework/AzCore/AzCore/Asset/SerializedAssetTracker.h b/Code/Framework/AzCore/AzCore/Asset/SerializedAssetTracker.h new file mode 100644 index 0000000000..e1b0af72e1 --- /dev/null +++ b/Code/Framework/AzCore/AzCore/Asset/SerializedAssetTracker.h @@ -0,0 +1,33 @@ +/* +* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or +* its licensors. +* +* For complete copyright and license terms please see the LICENSE at the root of this +* distribution (the "License"). All use of this software is governed by the License, +* or, if provided, by the license below or the license accompanying this file. Do not +* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* +*/ + +#pragma once + +#include +#include +namespace AZ +{ + namespace Data + { + class SerializedAssetTracker + { + public: + AZ_RTTI(SerializedAssetTracker, "{1E067091-8C0A-44B1-A455-6E97663F6963}"); + + void AddAsset(Asset& asset); + const AZStd::vector>& GetTrackedAssets() const; + + private: + AZStd::vector> m_serializedAssets; + }; + } +} diff --git a/Code/Framework/AzToolsFramework/AzToolsFramework/Prefab/PrefabDomUtils.cpp b/Code/Framework/AzToolsFramework/AzToolsFramework/Prefab/PrefabDomUtils.cpp index ae1737f907..9163b681de 100644 --- a/Code/Framework/AzToolsFramework/AzToolsFramework/Prefab/PrefabDomUtils.cpp +++ b/Code/Framework/AzToolsFramework/AzToolsFramework/Prefab/PrefabDomUtils.cpp @@ -118,7 +118,7 @@ namespace AzToolsFramework } bool LoadInstanceFromPrefabDom( - Instance& instance, const PrefabDom& prefabDom, AZStd::vector>& loadedAssets, LoadInstanceFlags flags) + Instance& instance, const PrefabDom& prefabDom, AZStd::vector>& referencedAssets, LoadInstanceFlags flags) { // When entities are rebuilt they are first destroyed. As a result any assets they were exclusively holding on to will // be released and reloaded once the entities are built up again. By suspending asset release temporarily the asset reload @@ -156,7 +156,7 @@ namespace AzToolsFramework return false; } - loadedAssets = assetTracker.GetTrackedAssets(); + referencedAssets = AZStd::move(assetTracker.GetTrackedAssets()); return true; } diff --git a/Code/Framework/AzToolsFramework/AzToolsFramework/Prefab/PrefabDomUtils.h b/Code/Framework/AzToolsFramework/AzToolsFramework/Prefab/PrefabDomUtils.h index 1f000c2f70..c0992abda9 100644 --- a/Code/Framework/AzToolsFramework/AzToolsFramework/Prefab/PrefabDomUtils.h +++ b/Code/Framework/AzToolsFramework/AzToolsFramework/Prefab/PrefabDomUtils.h @@ -76,7 +76,8 @@ namespace AzToolsFramework * @return bool on whether the operation succeeded. */ bool LoadInstanceFromPrefabDom( - Instance& instance, const PrefabDom& prefabDom, AZStd::vector>& loadedAssets, LoadInstanceFlags flags = LoadInstanceFlags::None); + Instance& instance, const PrefabDom& prefabDom, AZStd::vector>& referencedAssets, + LoadInstanceFlags flags = LoadInstanceFlags::None); /** * Loads a valid Prefab Instance from a Prefab Dom. Useful for generating Instances. diff --git a/Code/Framework/AzToolsFramework/AzToolsFramework/Prefab/Spawnable/PrefabCatchmentProcessor.cpp b/Code/Framework/AzToolsFramework/AzToolsFramework/Prefab/Spawnable/PrefabCatchmentProcessor.cpp index 9ae795dbf1..a89b364471 100644 --- a/Code/Framework/AzToolsFramework/AzToolsFramework/Prefab/Spawnable/PrefabCatchmentProcessor.cpp +++ b/Code/Framework/AzToolsFramework/AzToolsFramework/Prefab/Spawnable/PrefabCatchmentProcessor.cpp @@ -20,8 +20,6 @@ #include #include -#include - namespace AzToolsFramework::Prefab::PrefabConversionUtils { void PrefabCatchmentProcessor::Process(PrefabProcessorContext& context) @@ -65,7 +63,6 @@ namespace AzToolsFramework::Prefab::PrefabConversionUtils AZStd::move(uniqueName), context.GetSourceUuid(), AZStd::move(serializer)); AZ_Assert(spawnable, "Failed to create a new spawnable."); - Prefab::PrefabDomUtils::PrintPrefabDomValue("Prefab used for spawnable", prefab); bool result = SpawnableUtils::CreateSpawnable(*spawnable, prefab, object.GetReferencedAssets()); if (result) { From 4c0fdf78bcfe5918d4ac69a93db44d5f401b3e58 Mon Sep 17 00:00:00 2001 From: sconel Date: Mon, 10 May 2021 12:56:54 -0700 Subject: [PATCH 03/11] Added error messaging, cleaned up LoadReferencedAssets --- .../Entity/PrefabEditorEntityOwnershipService.cpp | 7 ++++++- .../Entity/PrefabEditorEntityOwnershipService.h | 2 ++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/Code/Framework/AzToolsFramework/AzToolsFramework/Entity/PrefabEditorEntityOwnershipService.cpp b/Code/Framework/AzToolsFramework/AzToolsFramework/Entity/PrefabEditorEntityOwnershipService.cpp index a4e9d207be..0206875418 100644 --- a/Code/Framework/AzToolsFramework/AzToolsFramework/Entity/PrefabEditorEntityOwnershipService.cpp +++ b/Code/Framework/AzToolsFramework/AzToolsFramework/Entity/PrefabEditorEntityOwnershipService.cpp @@ -343,12 +343,13 @@ namespace AzToolsFramework m_validateEntitiesCallback = AZStd::move(validateEntitiesCallback); } - void LoadReferencedAssets(AZStd::vector>& referencedAssets) + void PrefabEditorEntityOwnershipService::LoadReferencedAssets(AZStd::vector>& referencedAssets) { for (AZ::Data::Asset& asset : referencedAssets) { if (!asset.GetId().IsValid()) { + AZ_Error("Prefab", false, "Invalid asset found referenced in scene while entering game mode"); continue; } @@ -367,6 +368,7 @@ namespace AzToolsFramework if (!asset.GetId().IsValid()) { + AZ_Error("Prefab", false, "Invalid asset found referenced in scene while entering game mode"); continue; } @@ -376,6 +378,9 @@ namespace AzToolsFramework if (asset.IsError()) { + AZ_Error("Prefab", false, "Asset with id %s failed to preload while entering game mode", + asset.GetId().ToString().c_str()); + continue; } } diff --git a/Code/Framework/AzToolsFramework/AzToolsFramework/Entity/PrefabEditorEntityOwnershipService.h b/Code/Framework/AzToolsFramework/AzToolsFramework/Entity/PrefabEditorEntityOwnershipService.h index 9c483e61c5..48e07df091 100644 --- a/Code/Framework/AzToolsFramework/AzToolsFramework/Entity/PrefabEditorEntityOwnershipService.h +++ b/Code/Framework/AzToolsFramework/AzToolsFramework/Entity/PrefabEditorEntityOwnershipService.h @@ -199,6 +199,8 @@ namespace AzToolsFramework void OnEntityRemoved(AZ::EntityId entityId); + void LoadReferencedAssets(AZStd::vector>& referencedAssets); + OnEntitiesAddedCallback m_entitiesAddedCallback; OnEntitiesRemovedCallback m_entitiesRemovedCallback; ValidateEntitiesCallback m_validateEntitiesCallback; From 17ccf904801e1d0480670f6ef79277c03748d6b4 Mon Sep 17 00:00:00 2001 From: sconel Date: Mon, 10 May 2021 12:59:16 -0700 Subject: [PATCH 04/11] Updated function header comment --- .../AzToolsFramework/AzToolsFramework/Prefab/PrefabDomUtils.h | 1 + 1 file changed, 1 insertion(+) diff --git a/Code/Framework/AzToolsFramework/AzToolsFramework/Prefab/PrefabDomUtils.h b/Code/Framework/AzToolsFramework/AzToolsFramework/Prefab/PrefabDomUtils.h index c0992abda9..6778c236ee 100644 --- a/Code/Framework/AzToolsFramework/AzToolsFramework/Prefab/PrefabDomUtils.h +++ b/Code/Framework/AzToolsFramework/AzToolsFramework/Prefab/PrefabDomUtils.h @@ -71,6 +71,7 @@ namespace AzToolsFramework /** * Loads a valid Prefab Instance from a Prefab Dom. Useful for generating Instances. * @param instance The Instance to load. + * @param referencedAssets AZ::Assets discovered during json load are added to this list * @param prefabDom the prefabDom that will be used to load the Instance data. * @param shouldClearContainers whether to clear containers in Instance while loading. * @return bool on whether the operation succeeded. From 9255e4c1917c91396e678f8d3b9e54df842aeaab Mon Sep 17 00:00:00 2001 From: sconel Date: Mon, 10 May 2021 13:05:29 -0700 Subject: [PATCH 05/11] Added non const getter to SerializedAssetTracker --- .../Framework/AzCore/AzCore/Asset/SerializedAssetTracker.cpp | 5 +++++ Code/Framework/AzCore/AzCore/Asset/SerializedAssetTracker.h | 1 + 2 files changed, 6 insertions(+) diff --git a/Code/Framework/AzCore/AzCore/Asset/SerializedAssetTracker.cpp b/Code/Framework/AzCore/AzCore/Asset/SerializedAssetTracker.cpp index b3fad2431f..bdd89683f6 100644 --- a/Code/Framework/AzCore/AzCore/Asset/SerializedAssetTracker.cpp +++ b/Code/Framework/AzCore/AzCore/Asset/SerializedAssetTracker.cpp @@ -25,5 +25,10 @@ namespace AZ { return m_serializedAssets; } + + AZStd::vector>& SerializedAssetTracker::GetTrackedAssets() + { + return m_serializedAssets; + } } } diff --git a/Code/Framework/AzCore/AzCore/Asset/SerializedAssetTracker.h b/Code/Framework/AzCore/AzCore/Asset/SerializedAssetTracker.h index e1b0af72e1..ad80a077fe 100644 --- a/Code/Framework/AzCore/AzCore/Asset/SerializedAssetTracker.h +++ b/Code/Framework/AzCore/AzCore/Asset/SerializedAssetTracker.h @@ -24,6 +24,7 @@ namespace AZ AZ_RTTI(SerializedAssetTracker, "{1E067091-8C0A-44B1-A455-6E97663F6963}"); void AddAsset(Asset& asset); + AZStd::vector>& GetTrackedAssets(); const AZStd::vector>& GetTrackedAssets() const; private: From f7ea02afdcd554eac29a0d3b6101071bbeccd24d Mon Sep 17 00:00:00 2001 From: sconel Date: Mon, 10 May 2021 13:21:13 -0700 Subject: [PATCH 06/11] Fix for NetworkingProcessor using CreateSpawnable without ReferencedAssets arg --- .../AzToolsFramework/Prefab/Spawnable/SpawnableUtils.cpp | 6 ++++++ .../AzToolsFramework/Prefab/Spawnable/SpawnableUtils.h | 1 + 2 files changed, 7 insertions(+) diff --git a/Code/Framework/AzToolsFramework/AzToolsFramework/Prefab/Spawnable/SpawnableUtils.cpp b/Code/Framework/AzToolsFramework/AzToolsFramework/Prefab/Spawnable/SpawnableUtils.cpp index 085758cda9..716c3098d9 100644 --- a/Code/Framework/AzToolsFramework/AzToolsFramework/Prefab/Spawnable/SpawnableUtils.cpp +++ b/Code/Framework/AzToolsFramework/AzToolsFramework/Prefab/Spawnable/SpawnableUtils.cpp @@ -35,6 +35,12 @@ namespace AzToolsFramework::Prefab::SpawnableUtils return spawnable; } + bool CreateSpawnable(AzFramework::Spawnable& spawnable, const PrefabDom& prefabDom) + { + AZStd::vector> referencedAssets; + return CreateSpawnable(spawnable, prefabDom, referencedAssets); + } + bool CreateSpawnable(AzFramework::Spawnable& spawnable, const PrefabDom& prefabDom, AZStd::vector>& referencedAssets) { Instance instance; diff --git a/Code/Framework/AzToolsFramework/AzToolsFramework/Prefab/Spawnable/SpawnableUtils.h b/Code/Framework/AzToolsFramework/AzToolsFramework/Prefab/Spawnable/SpawnableUtils.h index c30e5ea77a..3b5ea488cb 100644 --- a/Code/Framework/AzToolsFramework/AzToolsFramework/Prefab/Spawnable/SpawnableUtils.h +++ b/Code/Framework/AzToolsFramework/AzToolsFramework/Prefab/Spawnable/SpawnableUtils.h @@ -18,6 +18,7 @@ namespace AzToolsFramework::Prefab::SpawnableUtils { AzFramework::Spawnable CreateSpawnable(const PrefabDom& prefabDom); + bool CreateSpawnable(AzFramework::Spawnable& spawnable, const PrefabDom& prefabDom); bool CreateSpawnable(AzFramework::Spawnable& spawnable, const PrefabDom& prefabDom, AZStd::vector>& referencedAssets); void SortEntitiesByTransformHierarchy(AzFramework::Spawnable& spawnable); From 93974dd1c51cfcde72fe187a2072f6ffeb499da7 Mon Sep 17 00:00:00 2001 From: sconel Date: Mon, 10 May 2021 14:22:48 -0700 Subject: [PATCH 07/11] Seperated queue load and blocking load calls so queue loads aren't interrupted. Added comment about asset dispatch events --- .../PrefabEditorEntityOwnershipService.cpp | 38 +++++++++++++------ 1 file changed, 27 insertions(+), 11 deletions(-) diff --git a/Code/Framework/AzToolsFramework/AzToolsFramework/Entity/PrefabEditorEntityOwnershipService.cpp b/Code/Framework/AzToolsFramework/AzToolsFramework/Entity/PrefabEditorEntityOwnershipService.cpp index 0206875418..6b6f1475bb 100644 --- a/Code/Framework/AzToolsFramework/AzToolsFramework/Entity/PrefabEditorEntityOwnershipService.cpp +++ b/Code/Framework/AzToolsFramework/AzToolsFramework/Entity/PrefabEditorEntityOwnershipService.cpp @@ -345,6 +345,7 @@ namespace AzToolsFramework void PrefabEditorEntityOwnershipService::LoadReferencedAssets(AZStd::vector>& referencedAssets) { + // Start our loads on all assets by calling GetAsset from the AssetManager for (AZ::Data::Asset& asset : referencedAssets) { if (!asset.GetId().IsValid()) @@ -362,7 +363,6 @@ namespace AzToolsFramework AZ::Data::AssetId assetId = asset.GetId(); AZ::Data::AssetType assetType = asset.GetType(); - const bool blockingLoad = loadBehavior == AZ::Data::AssetLoadBehavior::PreLoad; asset = AZ::Data::AssetManager::Instance().GetAsset(assetId, assetType, loadBehavior); @@ -371,18 +371,33 @@ namespace AzToolsFramework AZ_Error("Prefab", false, "Invalid asset found referenced in scene while entering game mode"); continue; } + } - if (blockingLoad) + // For all Preload assets we block until they're ready + // We do this as a seperate pass so that we don't interrupt queuing up all other asset loads + for (AZ::Data::Asset& asset : referencedAssets) + { + if (!asset.GetId().IsValid()) { - asset.BlockUntilLoadComplete(); + AZ_Error("Prefab", false, "Invalid asset found referenced in scene while entering game mode"); + continue; + } - if (asset.IsError()) - { - AZ_Error("Prefab", false, "Asset with id %s failed to preload while entering game mode", - asset.GetId().ToString().c_str()); + const AZ::Data::AssetLoadBehavior loadBehavior = asset.GetAutoLoadBehavior(); - continue; - } + if (loadBehavior != AZ::Data::AssetLoadBehavior::PreLoad) + { + continue; + } + + asset.BlockUntilLoadComplete(); + + if (asset.IsError()) + { + AZ_Error("Prefab", false, "Asset with id %s failed to preload while entering game mode", + asset.GetId().ToString().c_str()); + + continue; } } } @@ -438,6 +453,9 @@ namespace AzToolsFramework m_playInEditorData.m_assets.emplace_back(product.ReleaseAsset().release(), AZ::Data::AssetLoadBehavior::Default); } + // 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(); if (rootSpawnableIndex != NoRootSpawnable) { @@ -445,8 +463,6 @@ namespace AzToolsFramework m_playInEditorData.m_entities.SpawnAllEntities(); } - AZ::Data::AssetManager::Instance().DispatchEvents(); - // This is a workaround until the replacement for GameEntityContext is done AzFramework::GameEntityContextEventBus::Broadcast( &AzFramework::GameEntityContextEventBus::Events::OnGameEntitiesStarted); From 36911723c2b9054468db629a23fa5cc9b1dfbc8d Mon Sep 17 00:00:00 2001 From: sconel Date: Mon, 10 May 2021 18:17:39 -0700 Subject: [PATCH 08/11] Addressed PR feedback --- .../AzCore/Asset/AssetJsonSerializer.cpp | 24 ++++++++++--- .../AzCore/AzCore/Asset/AssetJsonSerializer.h | 14 ++++++++ .../AzCore/Asset/SerializedAssetTracker.cpp | 34 ------------------- .../AzCore/Asset/SerializedAssetTracker.h | 34 ------------------- .../AzCore/AzCore/azcore_files.cmake | 2 -- .../Prefab/PrefabDomUtils.cpp | 9 +++-- .../AzToolsFramework/Prefab/PrefabDomUtils.h | 14 ++++---- 7 files changed, 44 insertions(+), 87 deletions(-) delete mode 100644 Code/Framework/AzCore/AzCore/Asset/SerializedAssetTracker.cpp delete mode 100644 Code/Framework/AzCore/AzCore/Asset/SerializedAssetTracker.h diff --git a/Code/Framework/AzCore/AzCore/Asset/AssetJsonSerializer.cpp b/Code/Framework/AzCore/AzCore/Asset/AssetJsonSerializer.cpp index 6968b51025..0078abf2d1 100644 --- a/Code/Framework/AzCore/AzCore/Asset/AssetJsonSerializer.cpp +++ b/Code/Framework/AzCore/AzCore/Asset/AssetJsonSerializer.cpp @@ -12,7 +12,6 @@ #include #include -#include #include #include #include @@ -112,8 +111,8 @@ namespace AZ AssetId id; JSR::ResultCode result(JSR::Tasks::ReadField); - SerializedAssetTracker** assetIdTracker = - context.GetMetadata().Find(); + SerializedAssetTracker* assetTracker = + context.GetMetadata().Find(); { Data::AssetLoadBehavior loadBehavior = instance->GetAutoLoadBehavior(); @@ -168,9 +167,9 @@ namespace AZ "The asset hint is missing for Asset, so it will be left empty.")); } - if (assetIdTracker && *assetIdTracker) + if (assetTracker) { - (*assetIdTracker)->AddAsset(*instance); + assetTracker->AddAsset(*instance); } bool success = result.GetOutcome() <= JSR::Outcomes::PartialSkip; @@ -181,5 +180,20 @@ namespace AZ "Not enough information was available to create an instance of Asset or data was corrupted."; return context.Report(result, message); } + + void SerializedAssetTracker::AddAsset(Asset& asset) + { + m_serializedAssets.emplace_back(asset); + } + + const AZStd::vector>& SerializedAssetTracker::GetTrackedAssets() const + { + return m_serializedAssets; + } + + AZStd::vector>& SerializedAssetTracker::GetTrackedAssets() + { + return m_serializedAssets; + } } // namespace Data } // namespace AZ diff --git a/Code/Framework/AzCore/AzCore/Asset/AssetJsonSerializer.h b/Code/Framework/AzCore/AzCore/Asset/AssetJsonSerializer.h index 3d5271035c..dca12df21b 100644 --- a/Code/Framework/AzCore/AzCore/Asset/AssetJsonSerializer.h +++ b/Code/Framework/AzCore/AzCore/Asset/AssetJsonSerializer.h @@ -13,6 +13,7 @@ #pragma once #include +#include #include namespace AZ @@ -37,5 +38,18 @@ namespace AZ private: JsonSerializationResult::Result LoadAsset(void* outputValue, const rapidjson::Value& inputValue, JsonDeserializerContext& context); }; + + class SerializedAssetTracker + { + public: + AZ_RTTI(SerializedAssetTracker, "{1E067091-8C0A-44B1-A455-6E97663F6963}"); + + void AddAsset(Asset& asset); + AZStd::vector>& GetTrackedAssets(); + const AZStd::vector>& GetTrackedAssets() const; + + private: + AZStd::vector> m_serializedAssets; + }; } // namespace Data } // namespace AZ diff --git a/Code/Framework/AzCore/AzCore/Asset/SerializedAssetTracker.cpp b/Code/Framework/AzCore/AzCore/Asset/SerializedAssetTracker.cpp deleted file mode 100644 index bdd89683f6..0000000000 --- a/Code/Framework/AzCore/AzCore/Asset/SerializedAssetTracker.cpp +++ /dev/null @@ -1,34 +0,0 @@ -/* -* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or -* its licensors. -* -* For complete copyright and license terms please see the LICENSE at the root of this -* distribution (the "License"). All use of this software is governed by the License, -* or, if provided, by the license below or the license accompanying this file. Do not -* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* -*/ - -#include - -namespace AZ -{ - namespace Data - { - void SerializedAssetTracker::AddAsset(Asset& asset) - { - m_serializedAssets.emplace_back(asset); - } - - const AZStd::vector>& SerializedAssetTracker::GetTrackedAssets() const - { - return m_serializedAssets; - } - - AZStd::vector>& SerializedAssetTracker::GetTrackedAssets() - { - return m_serializedAssets; - } - } -} diff --git a/Code/Framework/AzCore/AzCore/Asset/SerializedAssetTracker.h b/Code/Framework/AzCore/AzCore/Asset/SerializedAssetTracker.h deleted file mode 100644 index ad80a077fe..0000000000 --- a/Code/Framework/AzCore/AzCore/Asset/SerializedAssetTracker.h +++ /dev/null @@ -1,34 +0,0 @@ -/* -* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or -* its licensors. -* -* For complete copyright and license terms please see the LICENSE at the root of this -* distribution (the "License"). All use of this software is governed by the License, -* or, if provided, by the license below or the license accompanying this file. Do not -* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* -*/ - -#pragma once - -#include -#include -namespace AZ -{ - namespace Data - { - class SerializedAssetTracker - { - public: - AZ_RTTI(SerializedAssetTracker, "{1E067091-8C0A-44B1-A455-6E97663F6963}"); - - void AddAsset(Asset& asset); - AZStd::vector>& GetTrackedAssets(); - const AZStd::vector>& GetTrackedAssets() const; - - private: - AZStd::vector> m_serializedAssets; - }; - } -} diff --git a/Code/Framework/AzCore/AzCore/azcore_files.cmake b/Code/Framework/AzCore/AzCore/azcore_files.cmake index c6ad90200b..5357ed66a6 100644 --- a/Code/Framework/AzCore/AzCore/azcore_files.cmake +++ b/Code/Framework/AzCore/AzCore/azcore_files.cmake @@ -35,8 +35,6 @@ set(FILES Asset/AssetSerializer.h Asset/AssetTypeInfoBus.h Asset/AssetInternal/WeakAsset.h - Asset/SerializedAssetTracker.cpp - Asset/SerializedAssetTracker.h Casting/lossy_cast.h Casting/numeric_cast.h Component/Component.cpp diff --git a/Code/Framework/AzToolsFramework/AzToolsFramework/Prefab/PrefabDomUtils.cpp b/Code/Framework/AzToolsFramework/AzToolsFramework/Prefab/PrefabDomUtils.cpp index 9163b681de..0bffd26be0 100644 --- a/Code/Framework/AzToolsFramework/AzToolsFramework/Prefab/PrefabDomUtils.cpp +++ b/Code/Framework/AzToolsFramework/AzToolsFramework/Prefab/PrefabDomUtils.cpp @@ -11,7 +11,7 @@ */ #include -#include +#include #include #include @@ -132,15 +132,13 @@ namespace AzToolsFramework entityIdMapper.SetEntityIdGenerationApproach(InstanceEntityIdMapper::EntityIdGenerationApproach::Random); } - AZ::Data::SerializedAssetTracker assetTracker; - AZ::JsonDeserializerSettings settings; // The InstanceEntityIdMapper is registered twice because it's used in several places during deserialization where one is // specific for the InstanceEntityIdMapper and once for the generic JsonEntityIdMapper. Because the Json Serializer's meta // data has strict typing and doesn't look for inheritance both have to be explicitly added so they're found both locations. settings.m_metadata.Add(static_cast(&entityIdMapper)); settings.m_metadata.Add(&entityIdMapper); - settings.m_metadata.Add(&assetTracker); + settings.m_metadata.Create(); AZ::JsonSerializationResult::ResultCode result = AZ::JsonSerialization::Load(instance, prefabDom, settings); @@ -155,8 +153,9 @@ namespace AzToolsFramework return false; } + AZ::Data::SerializedAssetTracker* assetTracker = settings.m_metadata.Find(); - referencedAssets = AZStd::move(assetTracker.GetTrackedAssets()); + referencedAssets = AZStd::move(assetTracker->GetTrackedAssets()); return true; } diff --git a/Code/Framework/AzToolsFramework/AzToolsFramework/Prefab/PrefabDomUtils.h b/Code/Framework/AzToolsFramework/AzToolsFramework/Prefab/PrefabDomUtils.h index 6778c236ee..c7c2827770 100644 --- a/Code/Framework/AzToolsFramework/AzToolsFramework/Prefab/PrefabDomUtils.h +++ b/Code/Framework/AzToolsFramework/AzToolsFramework/Prefab/PrefabDomUtils.h @@ -43,7 +43,7 @@ namespace AzToolsFramework /** * Stores a valid Prefab Instance within a Prefab Dom. Useful for generating Templates * @param instance The instance to store - * @param prefabDom the prefabDom that will be used to store the Instance data + * @param prefabDom The prefabDom that will be used to store the Instance data * @return bool on whether the operation succeeded */ bool StoreInstanceInPrefabDom(const Instance& instance, PrefabDom& prefabDom); @@ -61,8 +61,8 @@ namespace AzToolsFramework /** * Loads a valid Prefab Instance from a Prefab Dom. Useful for generating Instances. * @param instance The Instance to load. - * @param prefabDom the prefabDom that will be used to load the Instance data. - * @param shouldClearContainers whether to clear containers in Instance while loading. + * @param prefabDom The prefabDom that will be used to load the Instance data. + * @param shouldClearContainers Whether to clear containers in Instance while loading. * @return bool on whether the operation succeeded. */ bool LoadInstanceFromPrefabDom( @@ -72,8 +72,8 @@ namespace AzToolsFramework * Loads a valid Prefab Instance from a Prefab Dom. Useful for generating Instances. * @param instance The Instance to load. * @param referencedAssets AZ::Assets discovered during json load are added to this list - * @param prefabDom the prefabDom that will be used to load the Instance data. - * @param shouldClearContainers whether to clear containers in Instance while loading. + * @param prefabDom The prefabDom that will be used to load the Instance data. + * @param shouldClearContainers Whether to clear containers in Instance while loading. * @return bool on whether the operation succeeded. */ bool LoadInstanceFromPrefabDom( @@ -85,8 +85,8 @@ namespace AzToolsFramework * @param instance The Instance to load. * @param newlyAddedEntities The new instances added during deserializing the instance. These are the entities found * in the prefabDom. - * @param prefabDom the prefabDom that will be used to load the Instance data. - * @param shouldClearContainers whether to clear containers in Instance while loading. + * @param prefabDom The prefabDom that will be used to load the Instance data. + * @param shouldClearContainers Whether to clear containers in Instance while loading. * @return bool on whether the operation succeeded. */ bool LoadInstanceFromPrefabDom( From 12fb07c3e32289707616bf66563b95a79b66b46e Mon Sep 17 00:00:00 2001 From: sconel Date: Mon, 10 May 2021 18:56:29 -0700 Subject: [PATCH 09/11] Fix for failing AssetJsonSerializer conformity tests --- Code/Framework/AzCore/AzCore/Asset/AssetJsonSerializer.cpp | 2 +- Code/Framework/AzCore/Tests/AssetJsonSerializerTests.cpp | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/Code/Framework/AzCore/AzCore/Asset/AssetJsonSerializer.cpp b/Code/Framework/AzCore/AzCore/Asset/AssetJsonSerializer.cpp index 0078abf2d1..17b0cba09d 100644 --- a/Code/Framework/AzCore/AzCore/Asset/AssetJsonSerializer.cpp +++ b/Code/Framework/AzCore/AzCore/Asset/AssetJsonSerializer.cpp @@ -129,7 +129,7 @@ namespace AZ if (it != inputValue.MemberEnd()) { ScopedContextPath subPath(context, "assetId"); - result = ContinueLoading(&id, azrtti_typeid(), it->value, context); + result.Combine(ContinueLoading(&id, azrtti_typeid(), it->value, context)); if (!id.m_guid.IsNull()) { *instance = AssetManager::Instance().FindOrCreateAsset(id, instance->GetType(), instance->GetAutoLoadBehavior()); diff --git a/Code/Framework/AzCore/Tests/AssetJsonSerializerTests.cpp b/Code/Framework/AzCore/Tests/AssetJsonSerializerTests.cpp index a494207850..bacbc3649d 100644 --- a/Code/Framework/AzCore/Tests/AssetJsonSerializerTests.cpp +++ b/Code/Framework/AzCore/Tests/AssetJsonSerializerTests.cpp @@ -130,6 +130,7 @@ namespace JsonSerializationTests auto instance = AZStd::make_shared(); instance->Create(id, false); instance->SetHint("TestFile"); + instance->SetAutoLoadBehavior(AZ::Data::AssetLoadBehavior::PreLoad); return instance; } @@ -153,6 +154,7 @@ namespace JsonSerializationTests "guid": "{BBEAC89F-8BAD-4A9D-BF6E-D0DF84A8DFD6}", "subId": 1 }, + "loadBehavior": "PreLoad", "assetHint": "TestFile" })"; } From 5cff7994bfce1a1ddce2f6199ff9e1775786458e Mon Sep 17 00:00:00 2001 From: sconel Date: Mon, 10 May 2021 19:00:24 -0700 Subject: [PATCH 10/11] Small update to AssetJsonSerializer result assignment --- Code/Framework/AzCore/AzCore/Asset/AssetJsonSerializer.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Code/Framework/AzCore/AzCore/Asset/AssetJsonSerializer.cpp b/Code/Framework/AzCore/AzCore/Asset/AssetJsonSerializer.cpp index 17b0cba09d..555eedf034 100644 --- a/Code/Framework/AzCore/AzCore/Asset/AssetJsonSerializer.cpp +++ b/Code/Framework/AzCore/AzCore/Asset/AssetJsonSerializer.cpp @@ -117,10 +117,10 @@ namespace AZ { Data::AssetLoadBehavior loadBehavior = instance->GetAutoLoadBehavior(); - result.Combine( + result = ContinueLoadingFromJsonObjectField(&loadBehavior, azrtti_typeid(), - inputValue, "loadBehavior", context)); + inputValue, "loadBehavior", context); instance->SetAutoLoadBehavior(loadBehavior); } From 286a1aafa984519cb67eda776216362796ec2bb1 Mon Sep 17 00:00:00 2001 From: sconel Date: Mon, 10 May 2021 19:11:51 -0700 Subject: [PATCH 11/11] Clang build fix --- Code/Framework/AzCore/AzCore/Asset/AssetJsonSerializer.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Code/Framework/AzCore/AzCore/Asset/AssetJsonSerializer.h b/Code/Framework/AzCore/AzCore/Asset/AssetJsonSerializer.h index dca12df21b..780066cd42 100644 --- a/Code/Framework/AzCore/AzCore/Asset/AssetJsonSerializer.h +++ b/Code/Framework/AzCore/AzCore/Asset/AssetJsonSerializer.h @@ -39,7 +39,7 @@ namespace AZ JsonSerializationResult::Result LoadAsset(void* outputValue, const rapidjson::Value& inputValue, JsonDeserializerContext& context); }; - class SerializedAssetTracker + class SerializedAssetTracker final { public: AZ_RTTI(SerializedAssetTracker, "{1E067091-8C0A-44B1-A455-6E97663F6963}");