diff --git a/AutomatedTesting/Registry/physx_overrides/Collider_AddingNewGroupWorks.setreg_override b/AutomatedTesting/Registry/physx_overrides/Collider_AddingNewGroupWorks.setreg_override index 7065f0dfeb..209e9a9feb 100644 --- a/AutomatedTesting/Registry/physx_overrides/Collider_AddingNewGroupWorks.setreg_override +++ b/AutomatedTesting/Registry/physx_overrides/Collider_AddingNewGroupWorks.setreg_override @@ -109,7 +109,7 @@ }, "MaterialLibrary": { "assetId": { - "guid": "{62446378-67F8-5E49-AC31-761DD5942695}" + "guid": "{7CDF49C3-91A2-5C4E-B642-6D1AEC80E70E}" }, "loadBehavior": "QueueLoad", "assetHint": "assets/physics/surfacetypemateriallibrary.physmaterial" diff --git a/AutomatedTesting/Registry/physx_overrides/Collider_CollisionGroupsWorkflow.setreg_override b/AutomatedTesting/Registry/physx_overrides/Collider_CollisionGroupsWorkflow.setreg_override index b82acaf0ae..65f15f8554 100644 --- a/AutomatedTesting/Registry/physx_overrides/Collider_CollisionGroupsWorkflow.setreg_override +++ b/AutomatedTesting/Registry/physx_overrides/Collider_CollisionGroupsWorkflow.setreg_override @@ -121,7 +121,7 @@ }, "MaterialLibrary": { "assetId": { - "guid": "{62446378-67F8-5E49-AC31-761DD5942695}" + "guid": "{7CDF49C3-91A2-5C4E-B642-6D1AEC80E70E}" }, "loadBehavior": "QueueLoad", "assetHint": "assets/physics/surfacetypemateriallibrary.physmaterial" diff --git a/AutomatedTesting/Registry/physx_overrides/Collider_DiffCollisionGroupDiffCollidingLayersNotCollide.setreg_override b/AutomatedTesting/Registry/physx_overrides/Collider_DiffCollisionGroupDiffCollidingLayersNotCollide.setreg_override index b82acaf0ae..65f15f8554 100644 --- a/AutomatedTesting/Registry/physx_overrides/Collider_DiffCollisionGroupDiffCollidingLayersNotCollide.setreg_override +++ b/AutomatedTesting/Registry/physx_overrides/Collider_DiffCollisionGroupDiffCollidingLayersNotCollide.setreg_override @@ -121,7 +121,7 @@ }, "MaterialLibrary": { "assetId": { - "guid": "{62446378-67F8-5E49-AC31-761DD5942695}" + "guid": "{7CDF49C3-91A2-5C4E-B642-6D1AEC80E70E}" }, "loadBehavior": "QueueLoad", "assetHint": "assets/physics/surfacetypemateriallibrary.physmaterial" diff --git a/AutomatedTesting/Registry/physx_overrides/Collider_NoneCollisionGroupSameLayerNotCollide.setreg_override b/AutomatedTesting/Registry/physx_overrides/Collider_NoneCollisionGroupSameLayerNotCollide.setreg_override index b82acaf0ae..65f15f8554 100644 --- a/AutomatedTesting/Registry/physx_overrides/Collider_NoneCollisionGroupSameLayerNotCollide.setreg_override +++ b/AutomatedTesting/Registry/physx_overrides/Collider_NoneCollisionGroupSameLayerNotCollide.setreg_override @@ -121,7 +121,7 @@ }, "MaterialLibrary": { "assetId": { - "guid": "{62446378-67F8-5E49-AC31-761DD5942695}" + "guid": "{7CDF49C3-91A2-5C4E-B642-6D1AEC80E70E}" }, "loadBehavior": "QueueLoad", "assetHint": "assets/physics/surfacetypemateriallibrary.physmaterial" diff --git a/AutomatedTesting/Registry/physx_overrides/Collider_SameCollisionGroupSameCustomLayerCollide.setreg_override b/AutomatedTesting/Registry/physx_overrides/Collider_SameCollisionGroupSameCustomLayerCollide.setreg_override index b82acaf0ae..65f15f8554 100644 --- a/AutomatedTesting/Registry/physx_overrides/Collider_SameCollisionGroupSameCustomLayerCollide.setreg_override +++ b/AutomatedTesting/Registry/physx_overrides/Collider_SameCollisionGroupSameCustomLayerCollide.setreg_override @@ -121,7 +121,7 @@ }, "MaterialLibrary": { "assetId": { - "guid": "{62446378-67F8-5E49-AC31-761DD5942695}" + "guid": "{7CDF49C3-91A2-5C4E-B642-6D1AEC80E70E}" }, "loadBehavior": "QueueLoad", "assetHint": "assets/physics/surfacetypemateriallibrary.physmaterial" diff --git a/AutomatedTesting/Registry/physxsystemconfiguration.setreg b/AutomatedTesting/Registry/physxsystemconfiguration.setreg index 83aad307a6..2ade83d769 100644 --- a/AutomatedTesting/Registry/physxsystemconfiguration.setreg +++ b/AutomatedTesting/Registry/physxsystemconfiguration.setreg @@ -103,7 +103,7 @@ }, "MaterialLibrary": { "assetId": { - "guid": "{62446378-67F8-5E49-AC31-761DD5942695}" + "guid": "{7CDF49C3-91A2-5C4E-B642-6D1AEC80E70E}" }, "loadBehavior": "QueueLoad", "assetHint": "assets/physics/surfacetypemateriallibrary.physmaterial" diff --git a/Gems/Blast/Code/Source/Components/BlastSystemComponent.cpp b/Gems/Blast/Code/Source/Components/BlastSystemComponent.cpp index 21ec1a4603..b7ee805b3c 100644 --- a/Gems/Blast/Code/Source/Components/BlastSystemComponent.cpp +++ b/Gems/Blast/Code/Source/Components/BlastSystemComponent.cpp @@ -286,8 +286,11 @@ namespace Blast DefaultConfigurationPath, globalConfiguration); AZ_Warning("Blast", loaded, "Failed to load Blast configuration, initializing with default configs."); - SetGlobalConfiguration(globalConfiguration); - SaveConfiguration(); + ApplyGlobalConfiguration(globalConfiguration); + if (!loaded) + { + SaveConfiguration(); + } } void BlastSystemComponent::SaveConfiguration() @@ -394,8 +397,13 @@ namespace Blast void BlastSystemComponent::SetGlobalConfiguration(const BlastGlobalConfiguration& globalConfiguration) { - m_configuration = globalConfiguration; + ApplyGlobalConfiguration(globalConfiguration); SaveConfiguration(); + } + + void BlastSystemComponent::ApplyGlobalConfiguration(const BlastGlobalConfiguration& globalConfiguration) + { + m_configuration = globalConfiguration; { AZ::Data::Asset& materialLibrary = m_configuration.m_materialLibrary; diff --git a/Gems/Blast/Code/Source/Components/BlastSystemComponent.h b/Gems/Blast/Code/Source/Components/BlastSystemComponent.h index a43bc17aca..8f6c200870 100644 --- a/Gems/Blast/Code/Source/Components/BlastSystemComponent.h +++ b/Gems/Blast/Code/Source/Components/BlastSystemComponent.h @@ -93,6 +93,7 @@ namespace Blast void InitPhysics(); void DeactivatePhysics(); + void ApplyGlobalConfiguration(const BlastGlobalConfiguration& materialLibrary); void RegisterCommands(); // Internal helper functions & classes diff --git a/Gems/PhysX/Code/Editor/Source/Components/EditorSystemComponent.cpp b/Gems/PhysX/Code/Editor/Source/Components/EditorSystemComponent.cpp index f65768cec9..a5b6430591 100644 --- a/Gems/PhysX/Code/Editor/Source/Components/EditorSystemComponent.cpp +++ b/Gems/PhysX/Code/Editor/Source/Components/EditorSystemComponent.cpp @@ -8,7 +8,9 @@ #include "EditorSystemComponent.h" #include +#include #include +#include #include #include #include @@ -23,7 +25,7 @@ namespace PhysX { - constexpr const char* DefaultAssetFilePath = "Physics/SurfaceTypeMaterialLibrary"; + constexpr const char* DefaultAssetFilePath = "Assets/Physics/SurfaceTypeMaterialLibrary"; constexpr const char* TemplateAssetFilename = "PhysX/TemplateMaterialLibrary"; static AZStd::optional> GetMaterialLibraryTemplate() @@ -67,7 +69,7 @@ namespace PhysX assetId, &AZ::Data::AssetCatalogRequestBus::Events::GetAssetIdByPath, relativePath.c_str(), assetType, true /*autoRegisterIfNotFound*/); AZ::Data::Asset newAsset = - AZ::Data::AssetManager::Instance().GetAsset(assetId, assetType, AZ::Data::AssetLoadBehavior::Default); + AZ::Data::AssetManager::Instance().FindOrCreateAsset(assetId, assetType, AZ::Data::AssetLoadBehavior::Default); if (auto* newMaterialLibraryData = azrtti_cast(newAsset.GetData())) { @@ -138,6 +140,14 @@ namespace PhysX if (auto retrievedMaterialLibrary = RetrieveDefaultMaterialLibrary()) { physxSystem->UpdateMaterialLibrary(retrievedMaterialLibrary.value()); + + // After setting the default material library, save the physx configuration. + auto saveCallback = []([[maybe_unused]] const PhysXSystemConfiguration& config, [[maybe_unused]] PhysXSettingsRegistryManager::Result result) + { + AZ_Warning("PhysX", result == PhysXSettingsRegistryManager::Result::Success, + "Unable to save the PhysX configuration after setting default material library."); + }; + physxSystem->GetSettingsRegistryManager().SaveSystemConfiguration(physxSystem->GetPhysXConfiguration(), saveCallback); } } } @@ -236,11 +246,15 @@ namespace PhysX if (!resultAssetId.IsValid()) { // No file for the default material library, create it - const char* assetRoot = AZ::IO::FileIOBase::GetInstance()->GetAlias("@projectsourceassets@"); - AZStd::string fullPath; - AzFramework::StringFunc::Path::ConstructFull(assetRoot, DefaultAssetFilePath, assetExtension.c_str(), fullPath); + AZ::IO::Path fullPath; + if (auto settingsRegistry = AZ::SettingsRegistry::Get(); settingsRegistry != nullptr) + { + settingsRegistry->Get(fullPath.Native(), AZ::SettingsRegistryMergeUtils::FilePathKey_ProjectPath); + } + fullPath /= DefaultAssetFilePath; + fullPath.ReplaceExtension(AZ::IO::PathView(assetExtension)); - if (auto materialLibraryOpt = CreateMaterialLibrary(fullPath, relativePath)) + if (auto materialLibraryOpt = CreateMaterialLibrary(fullPath.Native(), relativePath)) { return materialLibraryOpt; } diff --git a/Gems/PhysX/Code/Source/System/PhysXSystem.cpp b/Gems/PhysX/Code/Source/System/PhysXSystem.cpp index ebdfc5d417..cc21285f8c 100644 --- a/Gems/PhysX/Code/Source/System/PhysXSystem.cpp +++ b/Gems/PhysX/Code/Source/System/PhysXSystem.cpp @@ -511,10 +511,12 @@ namespace PhysX materialLibrary.BlockUntilLoadComplete(); - AZ_Warning("PhysX", (materialLibrary.GetData() != nullptr), + const bool loadedSuccessfully = materialLibrary.GetData() != nullptr && !materialLibrary.IsError(); + + AZ_Warning("PhysX", loadedSuccessfully, "LoadDefaultMaterialLibrary: Default Material Library asset data is invalid."); - return materialLibrary.GetData() != nullptr && !materialLibrary.IsError(); + return loadedSuccessfully; } //TEMP -- until these are fully moved over here diff --git a/Gems/PhysX/Code/Source/SystemComponent.cpp b/Gems/PhysX/Code/Source/SystemComponent.cpp index 42c78d2c1d..f56ad43079 100644 --- a/Gems/PhysX/Code/Source/SystemComponent.cpp +++ b/Gems/PhysX/Code/Source/SystemComponent.cpp @@ -458,7 +458,13 @@ namespace PhysX { const PhysXSystemConfiguration defaultConfig = PhysXSystemConfiguration::CreateDefault(); m_physXSystem->Initialize(&defaultConfig); - registryManager.SaveSystemConfiguration(defaultConfig, {}); + + auto saveCallback = []([[maybe_unused]] const PhysXSystemConfiguration& config, [[maybe_unused]] PhysXSettingsRegistryManager::Result result) + { + AZ_Warning("PhysX", result == PhysXSettingsRegistryManager::Result::Success, + "Unable to save the default PhysX configuration."); + }; + registryManager.SaveSystemConfiguration(defaultConfig, saveCallback); } //Load the DefaultSceneConfig @@ -471,7 +477,13 @@ namespace PhysX { const AzPhysics::SceneConfiguration defaultConfig = AzPhysics::SceneConfiguration::CreateDefault(); m_physXSystem->UpdateDefaultSceneConfiguration(defaultConfig); - registryManager.SaveDefaultSceneConfiguration(defaultConfig, {}); + + auto saveCallback = []([[maybe_unused]] const AzPhysics::SceneConfiguration& config, [[maybe_unused]] PhysXSettingsRegistryManager::Result result) + { + AZ_Warning("PhysX", result == PhysXSettingsRegistryManager::Result::Success, + "Unable to save the default Scene configuration."); + }; + registryManager.SaveDefaultSceneConfiguration(defaultConfig, saveCallback); } //load the debug configuration and initialize the PhysX debug interface @@ -486,7 +498,13 @@ namespace PhysX { const Debug::DebugConfiguration defaultConfig = Debug::DebugConfiguration::CreateDefault(); debug->Initialize(defaultConfig); - registryManager.SaveDebugConfiguration(defaultConfig, {}); + + auto saveCallback = []([[maybe_unused]] const Debug::DebugConfiguration& config, [[maybe_unused]] PhysXSettingsRegistryManager::Result result) + { + AZ_Warning("PhysX", result == PhysXSettingsRegistryManager::Result::Success, + "Unable to save the default PhysX Debug configuration."); + }; + registryManager.SaveDebugConfiguration(defaultConfig, saveCallback); } } }