From 93974dd1c51cfcde72fe187a2072f6ffeb499da7 Mon Sep 17 00:00:00 2001 From: sconel Date: Mon, 10 May 2021 14:22:48 -0700 Subject: [PATCH] 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);