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>
This commit is contained in:
amzn-sean
2021-08-17 13:48:51 +01:00
committed by GitHub
parent 3fb903b03b
commit d9ea329cbd
2 changed files with 20 additions and 4 deletions
@@ -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;
@@ -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<Physics::ShapeConfiguration> CloneCurrent() const;
private:
bool ShowingSubdivisionLevel() const;
AZ::u32 OnShapeTypeChanged();
AZ::u32 OnConfigurationChanged();
Physics::ShapeType m_lastShapeType = Physics::ShapeType::PhysicsAsset;
};
class EditorColliderComponentDescriptor;