diff --git a/com.unity.render-pipelines.high-definition/CHANGELOG.md b/com.unity.render-pipelines.high-definition/CHANGELOG.md index ef67484ccb4..5c1bc20a61c 100644 --- a/com.unity.render-pipelines.high-definition/CHANGELOG.md +++ b/com.unity.render-pipelines.high-definition/CHANGELOG.md @@ -41,6 +41,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. - Fixed sky override layer mask having no effect. - Fixed a memory leak in the template tutorial (1374640). - Fixed a build-time warning regarding light loop variants (case 1372256). +- Fixed an infinite import loop of materials when there is no HDMetaData generated by the ShaderGraph. ### Changed - Use RayTracingAccelerationStructure.CullInstances to filter Renderers and populate the acceleration structure with ray tracing instances for improved CPU performance on the main thread. diff --git a/com.unity.render-pipelines.high-definition/Editor/AssetProcessors/MaterialPostProcessor.cs b/com.unity.render-pipelines.high-definition/Editor/AssetProcessors/MaterialPostProcessor.cs index 784a3766c58..3dbb56982f3 100644 --- a/com.unity.render-pipelines.high-definition/Editor/AssetProcessors/MaterialPostProcessor.cs +++ b/com.unity.render-pipelines.high-definition/Editor/AssetProcessors/MaterialPostProcessor.cs @@ -286,6 +286,7 @@ class MaterialPostprocessor : AssetPostprocessor { internal static List s_CreatedAssets = new List(); internal static List s_ImportedAssetThatNeedSaving = new List(); + internal static Dictionary s_ImportedMaterialCounter = new Dictionary(); internal static bool s_NeedsSavingAssets = false; // Important: This should only be called by the RegisterUpgraderReimport(), ie the shadegraph/material version @@ -371,6 +372,14 @@ static void OnPostprocessAllAssets(string[] importedAssets, string[] deletedAsse // we would miss re-importing that dependency. if (MaterialReimporter.CheckHDShaderGraphVersionsForUpgrade("", material.shader, ignoreNonHDRPShaderGraphs: false)) { + s_ImportedMaterialCounter.TryGetValue(asset, out var importCounter); + s_ImportedMaterialCounter[asset] = ++importCounter; + + // CheckHDShaderGraphVersionsForUpgrade always return true if a ShaderGraph don't have an HDMetaData attached + // we need a check to avoid importing the same assets over and over again. + if (importCounter > 2) + continue; + var shaderPath = AssetDatabase.GetAssetPath(material.shader.GetInstanceID()); AssetDatabase.ImportAsset(shaderPath);