From d9ea329cbde12eb973a9942562c18ae40e5e052b Mon Sep 17 00:00:00 2001 From: amzn-sean <75276488+amzn-sean@users.noreply.github.com> Date: Tue, 17 Aug 2021 13:48:51 +0100 Subject: [PATCH] Fixes #2796 Collider retains phys mesh asset reference after changing to shape (#3162) Signed-off-by: amzn-sean <75276488+amzn-sean@users.noreply.github.com> --- .../PhysX/Code/Source/EditorColliderComponent.cpp | 15 ++++++++++++++- Gems/PhysX/Code/Source/EditorColliderComponent.h | 9 ++++++--- 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/Gems/PhysX/Code/Source/EditorColliderComponent.cpp b/Gems/PhysX/Code/Source/EditorColliderComponent.cpp index d3f1c63974..2445aba9bd 100644 --- a/Gems/PhysX/Code/Source/EditorColliderComponent.cpp +++ b/Gems/PhysX/Code/Source/EditorColliderComponent.cpp @@ -88,7 +88,7 @@ namespace PhysX ->EnumAttribute(Physics::ShapeType::Box, "Box") ->EnumAttribute(Physics::ShapeType::Capsule, "Capsule") ->EnumAttribute(Physics::ShapeType::PhysicsAsset, "PhysicsAsset") - ->Attribute(AZ::Edit::Attributes::ChangeNotify, AZ::Edit::PropertyRefreshLevels::EntireTree) + ->Attribute(AZ::Edit::Attributes::ChangeNotify, &EditorProxyShapeConfig::OnShapeTypeChanged) // note: we do not want the user to be able to change shape types while in ComponentMode (there will // potentially be different ComponentModes for different shape types) ->Attribute(AZ::Edit::Attributes::ReadOnly, &AzToolsFramework::ComponentModeFramework::InComponentMode) @@ -116,6 +116,19 @@ namespace PhysX } } + AZ::u32 EditorProxyShapeConfig::OnShapeTypeChanged() + { + //reset the physics asset if the shape type was Physics Asset + if (m_shapeType != Physics::ShapeType::PhysicsAsset && + m_lastShapeType == Physics::ShapeType::PhysicsAsset) + { + m_physicsAsset.m_pxAsset.Reset(); + m_physicsAsset.m_configuration = Physics::PhysicsAssetShapeConfiguration(); + } + m_lastShapeType = m_shapeType; + return AZ::Edit::PropertyRefreshLevels::EntireTree; + } + AZ::u32 EditorProxyShapeConfig::OnConfigurationChanged() { return AZ::Edit::PropertyRefreshLevels::ValuesOnly; diff --git a/Gems/PhysX/Code/Source/EditorColliderComponent.h b/Gems/PhysX/Code/Source/EditorColliderComponent.h index 8a78cc1cb8..50cf9d0c8b 100644 --- a/Gems/PhysX/Code/Source/EditorColliderComponent.h +++ b/Gems/PhysX/Code/Source/EditorColliderComponent.h @@ -58,8 +58,8 @@ namespace PhysX //! Proxy container for only displaying a specific shape configuration depending on the shapeType selected. struct EditorProxyShapeConfig { - AZ_CLASS_ALLOCATOR(EditorProxyShapeConfig, AZ::SystemAllocator, 0); - AZ_RTTI(EditorProxyShapeConfig, "{531FB42A-42A9-4234-89BA-FD349EF83D0C}"); + AZ_CLASS_ALLOCATOR(PhysX::EditorProxyShapeConfig, AZ::SystemAllocator, 0); + AZ_RTTI(PhysX::EditorProxyShapeConfig, "{531FB42A-42A9-4234-89BA-FD349EF83D0C}"); static void Reflect(AZ::ReflectContext* context); EditorProxyShapeConfig() = default; @@ -84,9 +84,12 @@ namespace PhysX AZStd::shared_ptr CloneCurrent() const; + private: bool ShowingSubdivisionLevel() const; - + AZ::u32 OnShapeTypeChanged(); AZ::u32 OnConfigurationChanged(); + + Physics::ShapeType m_lastShapeType = Physics::ShapeType::PhysicsAsset; }; class EditorColliderComponentDescriptor;