Skip to content

Commit 1a7ff0a

Browse files
Fixed an issue where changing the default volume profile from another inspector would not update the default volume editor. #6493
1 parent 7a231fc commit 1a7ff0a

File tree

4 files changed

+40
-8
lines changed

4 files changed

+40
-8
lines changed

com.unity.render-pipelines.core/Editor/Volume/VolumeComponentListEditor.cs

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,24 +16,24 @@ namespace UnityEditor.Rendering
1616
/// in the inspector:
1717
/// <code>
1818
/// using UnityEngine.Rendering;
19-
///
19+
///
2020
/// [CustomEditor(typeof(VolumeProfile))]
2121
/// public class CustomVolumeProfileEditor : Editor
2222
/// {
2323
/// VolumeComponentListEditor m_ComponentList;
24-
///
24+
///
2525
/// void OnEnable()
2626
/// {
2727
/// m_ComponentList = new VolumeComponentListEditor(this);
2828
/// m_ComponentList.Init(target as VolumeProfile, serializedObject);
2929
/// }
30-
///
30+
///
3131
/// void OnDisable()
3232
/// {
3333
/// if (m_ComponentList != null)
3434
/// m_ComponentList.Clear();
3535
/// }
36-
///
36+
///
3737
/// public override void OnInspectorGUI()
3838
/// {
3939
/// serializedObject.Update();
@@ -58,6 +58,8 @@ public sealed class VolumeComponentListEditor
5858
Dictionary<Type, Type> m_EditorTypes; // Component type => Editor type
5959
List<VolumeComponentEditor> m_Editors;
6060

61+
int m_CurrentHashCode;
62+
6163
/// <summary>
6264
/// Creates a new instance of <see cref="VolumeComponentListEditor"/> to use in an
6365
/// existing editor.
@@ -195,9 +197,12 @@ public void OnGUI()
195197
if (asset == null)
196198
return;
197199

198-
if (asset.isDirty)
200+
// Even if the asset is not dirty, the list of component may have been changed by another inspector.
201+
// In this case, only the hash will tell us that we need to refresh.
202+
if (asset.isDirty || asset.GetHashCode() != m_CurrentHashCode)
199203
{
200204
RefreshEditors();
205+
m_CurrentHashCode = asset.GetHashCode();
201206
asset.isDirty = false;
202207
}
203208

com.unity.render-pipelines.core/Runtime/Volume/VolumeProfile.cs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -279,5 +279,23 @@ public bool TryGetAllSubclassOf<T>(Type type, List<T> result)
279279

280280
return count != result.Count;
281281
}
282+
283+
284+
/// <summary>
285+
/// A custom hashing function that Unity uses to compare the state of parameters.
286+
/// </summary>
287+
/// <returns>A computed hash code for the current instance.</returns>
288+
public override int GetHashCode()
289+
{
290+
unchecked
291+
{
292+
int hash = 17;
293+
294+
for (int i = 0; i < components.Count; i++)
295+
hash = hash * 23 + components[i].GetHashCode();
296+
297+
return hash;
298+
}
299+
}
282300
}
283301
}

com.unity.render-pipelines.high-definition/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
8080
- Fixed a weird behavior in the scalable settings drawing when the space becomes tiny (1212045).
8181
- Fixed an usage of a a compute buffer not bound (1229964)
8282
- Fixed an issue where unncessarily serialized members in StaticLightingSky component would change each time the scene is changed.
83+
- Fixed an issue where changing the default volume profile from another inspector would not update the default volume editor.
8384

8485
### Changed
8586
- Renamed the cubemap used for diffuse convolution to a more explicit name for the memory profiler.

com.unity.render-pipelines.high-definition/Editor/RenderPipeline/Settings/DefaultSettingsPanel.cs

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ public class Styles
4545
ReorderableList m_BeforeTransparentCustomPostProcesses;
4646
ReorderableList m_BeforePostProcessCustomPostProcesses;
4747
ReorderableList m_AfterPostProcessCustomPostProcesses;
48+
int m_CurrentVolumeProfileHash;
4849

4950
public void OnGUI(string searchContext)
5051
{
@@ -207,6 +208,13 @@ void Draw_VolumeInspector()
207208
}
208209
EditorGUILayout.EndHorizontal();
209210

211+
// The state of the profile can change without the asset reference changing so in this case we need to reset the editor.
212+
if (m_CurrentVolumeProfileHash != asset.GetHashCode() && m_CachedDefaultVolumeProfileEditor != null)
213+
{
214+
m_CurrentVolumeProfileHash = asset.GetHashCode();
215+
m_CachedDefaultVolumeProfileEditor = null;
216+
}
217+
210218
Editor.CreateCachedEditor(asset, Type.GetType("UnityEditor.Rendering.VolumeProfileEditor"), ref m_CachedDefaultVolumeProfileEditor);
211219
EditorGUIUtility.labelWidth -= 18;
212220
bool oldEnabled = GUI.enabled;
@@ -230,13 +238,13 @@ void Draw_VolumeInspector()
230238
hdrpAsset.defaultLookDevProfile = newLookDevAsset;
231239
EditorUtility.SetDirty(hdrpAsset);
232240
}
233-
241+
234242
if (GUILayout.Button(EditorGUIUtility.TrTextContent("New", "Create a new Volume Profile for default in your default resource folder (defined in Wizard)"), GUILayout.Width(38), GUILayout.Height(18)))
235243
{
236244
DefaultVolumeProfileCreator.CreateAndAssign(DefaultVolumeProfileCreator.Kind.LookDev);
237245
}
238246
EditorGUILayout.EndHorizontal();
239-
247+
240248
Editor.CreateCachedEditor(lookDevAsset, Type.GetType("UnityEditor.Rendering.VolumeProfileEditor"), ref m_CachedLookDevVolumeProfileEditor);
241249
EditorGUIUtility.labelWidth -= 18;
242250
oldEnabled = GUI.enabled;
@@ -311,7 +319,7 @@ static string GetDefaultName(Kind kind)
311319
}
312320
return defaultName;
313321
}
314-
322+
315323
public static void CreateAndAssign(Kind kind)
316324
{
317325
var assetCreator = ScriptableObject.CreateInstance<DefaultVolumeProfileCreator>();

0 commit comments

Comments
 (0)