From 9a8063d683dc55df66ac32e9d7da829c6319c8d3 Mon Sep 17 00:00:00 2001 From: Pavlos Mavridis Date: Fri, 12 Jun 2020 16:03:35 +0200 Subject: [PATCH 1/3] fix warning in HDAdditionalLightData OnValidate --- .../Lighting/Light/HDAdditionalLightData.cs | 23 +++++++++++++------ 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/com.unity.render-pipelines.high-definition/Runtime/Lighting/Light/HDAdditionalLightData.cs b/com.unity.render-pipelines.high-definition/Runtime/Lighting/Light/HDAdditionalLightData.cs index 7577e93ad39..b489a5a4c9b 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/Lighting/Light/HDAdditionalLightData.cs +++ b/com.unity.render-pipelines.high-definition/Runtime/Lighting/Light/HDAdditionalLightData.cs @@ -1586,6 +1586,7 @@ internal Light legacyLight internal MeshRenderer emissiveMeshRenderer { get; private set; } #if UNITY_EDITOR + bool m_NeedsPrefabInstanceCheck = false; bool needRefreshPrefabInstanceEmissiveMeshes = false; #endif bool needRefreshEmissiveMeshesFromTimeLineUpdate = false; @@ -2282,6 +2283,18 @@ private void Start() m_Animated = GetComponent() != null; } + void Update() + { +#if UNITY_EDITOR + // If modification are due to change on prefab asset that are non overridden on this prefab instance + if (m_NeedsPrefabInstanceCheck && PrefabUtility.IsPartOfPrefabInstance(this) && ((PrefabUtility.GetCorrespondingObjectFromOriginalSource(this) as HDAdditionalLightData)?.needRefreshPrefabInstanceEmissiveMeshes ?? false)) + { + needRefreshPrefabInstanceEmissiveMeshes = true; + m_NeedsPrefabInstanceCheck = false; + } +#endif + } + // TODO: There are a lot of old != current checks and assignation in this function, maybe think about using another system ? void LateUpdate() { @@ -2499,13 +2512,9 @@ void OnValidate() RefreshCachedShadow(); #if UNITY_EDITOR - // If modification are due to change on prefab asset that are non overridden on this prefab instance - if (PrefabUtility.IsPartOfPrefabInstance(this) && ((PrefabUtility.GetCorrespondingObjectFromOriginalSource(this) as HDAdditionalLightData)?.needRefreshPrefabInstanceEmissiveMeshes ?? false)) - { - // As we cannot Create/Destroy in OnValidate, delay call to next Update - // To do this, wo set the same flag on prefab instances - needRefreshPrefabInstanceEmissiveMeshes = true; - } + // If modification are due to change on prefab asset, we want to have prefab instances to self-update, but we cannot check in OnValidate if this is part of + // prefab instance. So we delay the check on next update (and before teh LateUpdate logic) + m_NeedsPrefabInstanceCheck = true; #endif } From 91dc78e341d0ca36d45db874893b5c7ed52aabca Mon Sep 17 00:00:00 2001 From: Pavlos Mavridis Date: Fri, 12 Jun 2020 16:15:36 +0200 Subject: [PATCH 2/3] Changelog --- com.unity.render-pipelines.high-definition/CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/com.unity.render-pipelines.high-definition/CHANGELOG.md b/com.unity.render-pipelines.high-definition/CHANGELOG.md index fcb551ac2fd..5ef49c430af 100644 --- a/com.unity.render-pipelines.high-definition/CHANGELOG.md +++ b/com.unity.render-pipelines.high-definition/CHANGELOG.md @@ -679,6 +679,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. - Appropriately constraint blend distance of reflection probe while editing with the inspector (case 1248931) - Fixed AxF handling of roughness for Blinn-Phong type materials - Fixed AxF UI errors when surface type is switched to transparent +- Fixed warning in HDAdditionalLightData OnValidate (cases 1250864, 1244578) ### Changed - Improve MIP selection for decals on Transparents From 4ce7e1fc03231c87edf50ecd08cb8a296b84f2c8 Mon Sep 17 00:00:00 2001 From: Pavlos Mavridis Date: Mon, 15 Jun 2020 19:53:08 +0200 Subject: [PATCH 3/3] Avoid calling update --- .../Lighting/Light/HDAdditionalLightData.cs | 20 ++++++++----------- 1 file changed, 8 insertions(+), 12 deletions(-) diff --git a/com.unity.render-pipelines.high-definition/Runtime/Lighting/Light/HDAdditionalLightData.cs b/com.unity.render-pipelines.high-definition/Runtime/Lighting/Light/HDAdditionalLightData.cs index b489a5a4c9b..ada9de275ed 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/Lighting/Light/HDAdditionalLightData.cs +++ b/com.unity.render-pipelines.high-definition/Runtime/Lighting/Light/HDAdditionalLightData.cs @@ -2283,18 +2283,6 @@ private void Start() m_Animated = GetComponent() != null; } - void Update() - { -#if UNITY_EDITOR - // If modification are due to change on prefab asset that are non overridden on this prefab instance - if (m_NeedsPrefabInstanceCheck && PrefabUtility.IsPartOfPrefabInstance(this) && ((PrefabUtility.GetCorrespondingObjectFromOriginalSource(this) as HDAdditionalLightData)?.needRefreshPrefabInstanceEmissiveMeshes ?? false)) - { - needRefreshPrefabInstanceEmissiveMeshes = true; - m_NeedsPrefabInstanceCheck = false; - } -#endif - } - // TODO: There are a lot of old != current checks and assignation in this function, maybe think about using another system ? void LateUpdate() { @@ -2305,6 +2293,14 @@ void LateUpdate() #endif #if UNITY_EDITOR + + // If modification are due to change on prefab asset that are non overridden on this prefab instance + if (m_NeedsPrefabInstanceCheck && PrefabUtility.IsPartOfPrefabInstance(this) && ((PrefabUtility.GetCorrespondingObjectFromOriginalSource(this) as HDAdditionalLightData)?.needRefreshPrefabInstanceEmissiveMeshes ?? false)) + { + needRefreshPrefabInstanceEmissiveMeshes = true; + } + m_NeedsPrefabInstanceCheck = false; + // Update the list of overlapping lights for the LightOverlap scene view mode if (IsOverlapping()) s_overlappingHDLights.Add(this);