From 658c974db95675d6896c2c414f71ec9c3f186ddc Mon Sep 17 00:00:00 2001 From: dmcdiar Date: Wed, 30 Jun 2021 20:15:30 -0700 Subject: [PATCH] Properly handled reinitializing the cubemap asset when it is changed between Baked and Authored Signed-off-by: dmcdiar --- .../ReflectionProbeComponentController.cpp | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/Gems/AtomLyIntegration/CommonFeatures/Code/Source/ReflectionProbe/ReflectionProbeComponentController.cpp b/Gems/AtomLyIntegration/CommonFeatures/Code/Source/ReflectionProbe/ReflectionProbeComponentController.cpp index b2d842c82b..b99613e923 100644 --- a/Gems/AtomLyIntegration/CommonFeatures/Code/Source/ReflectionProbe/ReflectionProbeComponentController.cpp +++ b/Gems/AtomLyIntegration/CommonFeatures/Code/Source/ReflectionProbe/ReflectionProbeComponentController.cpp @@ -214,11 +214,25 @@ namespace AZ void ReflectionProbeComponentController::UpdateCubeMap() { + // disconnect the asset bus since we might reconnect with a different asset + Data::AssetBus::MultiHandler::BusDisconnect(); + Data::Asset& cubeMapAsset = m_configuration.m_useBakedCubemap ? m_configuration.m_bakedCubeMapAsset : m_configuration.m_authoredCubeMapAsset; - // this will invoke OnAssetReady() - Data::AssetBus::MultiHandler::BusConnect(cubeMapAsset.GetId()); + if (cubeMapAsset.GetId().IsValid()) + { + cubeMapAsset.QueueLoad(); + + // this will invoke OnAssetReady() + Data::AssetBus::MultiHandler::BusConnect(cubeMapAsset.GetId()); + } + else + { + // clear the current cubemap + Data::Instance image = nullptr; + m_featureProcessor->SetProbeCubeMap(m_handle, image, {}); + } } void ReflectionProbeComponentController::OnTransformChanged([[maybe_unused]] const AZ::Transform& local, const AZ::Transform& world)