diff --git a/Gems/AtomLyIntegration/CommonFeatures/Code/Source/Decals/EditorDecalComponent.cpp b/Gems/AtomLyIntegration/CommonFeatures/Code/Source/Decals/EditorDecalComponent.cpp index c5d61dd54a..02a2e1c0c9 100644 --- a/Gems/AtomLyIntegration/CommonFeatures/Code/Source/Decals/EditorDecalComponent.cpp +++ b/Gems/AtomLyIntegration/CommonFeatures/Code/Source/Decals/EditorDecalComponent.cpp @@ -15,6 +15,11 @@ namespace AZ { namespace Render { + static AZ::Data::Asset QueueLoad(const AZ::Data::AssetId id) + { + return AZ::Data::AssetManager::Instance().GetAsset(id, AZ::Data::AssetLoadBehavior::QueueLoad); + } + EditorDecalComponent::EditorDecalComponent(const DecalComponentConfig& config) : BaseClass(config) { @@ -87,16 +92,26 @@ namespace AZ AzFramework::EntityDebugDisplayEventBus::Handler::BusConnect(GetEntityId()); AzToolsFramework::EditorComponentSelectionRequestsBus::Handler::BusConnect(GetEntityId()); AzFramework::BoundsRequestBus::Handler::BusConnect(GetEntityId()); + CacheMaterial(); } void EditorDecalComponent::Deactivate() { + m_cachedMaterial = {}; AzFramework::BoundsRequestBus::Handler::BusDisconnect(); AzToolsFramework::EditorComponentSelectionRequestsBus::Handler::BusDisconnect(); AzFramework::EntityDebugDisplayEventBus::Handler::BusDisconnect(); BaseClass::Deactivate(); } + void EditorDecalComponent::CacheMaterial() + { + DecalComponentConfig decalComponentConfig; + GetConfiguration(decalComponentConfig); + const auto& materialAsset = decalComponentConfig.m_materialAsset; + m_cachedMaterial = QueueLoad(materialAsset.GetId()); + } + AZ::Transform EditorDecalComponent::GetWorldTransform() const { AZ::Transform transform = AZ::Transform::CreateIdentity(); @@ -193,6 +208,7 @@ namespace AZ u32 EditorDecalComponent::OnConfigurationChanged() { BaseClass::OnConfigurationChanged(); + CacheMaterial(); return Edit::PropertyRefreshLevels::AttributesAndValues; } diff --git a/Gems/AtomLyIntegration/CommonFeatures/Code/Source/Decals/EditorDecalComponent.h b/Gems/AtomLyIntegration/CommonFeatures/Code/Source/Decals/EditorDecalComponent.h index 1ca88d23fc..9878e72da0 100644 --- a/Gems/AtomLyIntegration/CommonFeatures/Code/Source/Decals/EditorDecalComponent.h +++ b/Gems/AtomLyIntegration/CommonFeatures/Code/Source/Decals/EditorDecalComponent.h @@ -64,6 +64,12 @@ namespace AZ //! EditorRenderComponentAdapter overrides ... u32 OnConfigurationChanged() override; + + // Hold onto the material for the lifespan of the EditorDecalComponent to smooth out performance. This is so we can avoid + // duplicate loads as the DecalTextureArrayFeatureProcessor will unload the materials after texture packing. + void CacheMaterial(); + + AZ::Data::Asset m_cachedMaterial; }; } // namespace Render } // namespace AZ