diff --git a/com.unity.render-pipelines.universal/CHANGELOG.md b/com.unity.render-pipelines.universal/CHANGELOG.md index 4a3425cfbc9..8c3015c7d38 100644 --- a/com.unity.render-pipelines.universal/CHANGELOG.md +++ b/com.unity.render-pipelines.universal/CHANGELOG.md @@ -4,6 +4,12 @@ All notable changes to this package will be documented in this file. The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html). +## [Unreleased] + +### Fixed +- Fixed an issue where ShadowCaster2Ds were sometimes being rendered twice in the editor while in playmode. + + ## [10.9.0] - 2021-12-06 ### Fixed diff --git a/com.unity.render-pipelines.universal/Runtime/2D/Shadows/ShadowCasterGroup2DManager.cs b/com.unity.render-pipelines.universal/Runtime/2D/Shadows/ShadowCasterGroup2DManager.cs index e90acc09857..72fa3657837 100644 --- a/com.unity.render-pipelines.universal/Runtime/2D/Shadows/ShadowCasterGroup2DManager.cs +++ b/com.unity.render-pipelines.universal/Runtime/2D/Shadows/ShadowCasterGroup2DManager.cs @@ -2,8 +2,15 @@ using System.Collections.Generic; using UnityEngine; +#if UNITY_EDITOR +using UnityEditor; +#endif + namespace UnityEngine.Experimental.Rendering.Universal { +#if UNITY_EDITOR + [InitializeOnLoadAttribute] +#endif internal class ShadowCasterGroup2DManager { static List s_ShadowCasterGroups = null; @@ -11,6 +18,20 @@ internal class ShadowCasterGroup2DManager public static List shadowCasterGroups { get { return s_ShadowCasterGroups; } } +#if UNITY_EDITOR + static ShadowCasterGroup2DManager() + { + EditorApplication.playModeStateChanged += OnPlayModeStateChanged; + } + + private static void OnPlayModeStateChanged(PlayModeStateChange state) + { + if (s_ShadowCasterGroups != null && (state == PlayModeStateChange.ExitingEditMode || state == PlayModeStateChange.ExitingPlayMode)) + s_ShadowCasterGroups.Clear(); + } + +#endif + public static void AddShadowCasterGroupToList(ShadowCasterGroup2D shadowCaster, List list) { int positionToInsert = 0;