Skip to content
This repository was archived by the owner on Nov 30, 2020. It is now read-only.

Commit 1ed5892

Browse files
TJHeuvelChman
authored andcommitted
Fixed a nullref when adding a new effect in a larger scene.
Adding a new effect can cause an infrequent nullreference: https://streamable.com/bk03b. Only seems to happen with large scenes, and only the first effect you add. The whole stacktrace is: ``` NullReferenceException: (null) UnityEditor.SerializedObject..ctor (UnityEngine.Object obj) (at C:/buildslave/unity/build/Editor/Mono/SerializedObject.cs:10) UnityEditor.Rendering.PostProcessing.PostProcessEffectBaseEditor.Init (UnityEngine.Rendering.PostProcessing.PostProcessEffectSettings target, UnityEditor.Editor inspector) (at Assets/Plugins/packages/PostProcessing/Editor/PostProcessEffectBaseEditor.cs:32) UnityEditor.Rendering.PostProcessing.EffectListEditor.CreateEditor (UnityEngine.Rendering.PostProcessing.PostProcessEffectSettings settings, UnityEditor.SerializedProperty property, Int32 index) (at Assets/Plugins/packages/PostProcessing/Editor/EffectListEditor.cs:86) UnityEditor.Rendering.PostProcessing.EffectListEditor.AddEffectOverride (System.Type type) (at Assets/Plugins/packages/PostProcessing/Editor/EffectListEditor.cs:231) UnityEditor.Rendering.PostProcessing.EffectListEditor+<OnGUI>c__AnonStorey1.<>m__0 () (at Assets/Plugins/packages/PostProcessing/Editor/EffectListEditor.cs:189) UnityEditor.GenericMenu.CatchMenu (System.Object userData, System.String[] options, Int32 selected) (at C:/buildslave/unity/build/artifacts/generated/common/editor/GenericMenuBindings.gen.cs:121) ``` The AddEffectOverride method calls AssetDatabase.SaveAssets, which causes the effect to be nullified. Probably there is some reloading going on? https://streamable.com/nlujr Moved the SaveAssets to the end of the method, added a comment to explain what and why.
1 parent a91372d commit 1ed5892

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

PostProcessing/Editor/EffectListEditor.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -214,17 +214,17 @@ void AddEffectOverride(Type type)
214214
var effectProp = m_SettingsProperty.GetArrayElementAtIndex(m_SettingsProperty.arraySize - 1);
215215
effectProp.objectReferenceValue = effect;
216216

217-
// Force save / refresh
217+
// Create & store the internal editor object for this effect
218+
CreateEditor(effect, effectProp);
219+
220+
m_SerializedObject.ApplyModifiedProperties();
221+
222+
// Force save / refresh. Important to do this last because SaveAssets can cause effect to become null!
218223
if (EditorUtility.IsPersistent(Asset))
219224
{
220225
EditorUtility.SetDirty(Asset);
221226
AssetDatabase.SaveAssets();
222227
}
223-
224-
// Create & store the internal editor object for this effect
225-
CreateEditor(effect, effectProp);
226-
227-
m_SerializedObject.ApplyModifiedProperties();
228228
}
229229

230230
void RemoveEffectOverride(int id)

0 commit comments

Comments
 (0)