Greetings!
I was hesitant to call this a bug as it maybe by design, but for backwards compatibility I think it qualifies.
The issue is I have a custom editor window. It reads prefabs and displays editors for specific components at specific times. So far this has worked for every other Unity I’ve needed to use within a custom editor. Except for the VisualEffect component.
This is the basic mechanism to check for changes within the editor window. It works for ParticleSystem, Transforms, etc, but not for the VisualEffect component.
EditorGUI.BeginChangeCheck();
visualEffectEditors[index].OnInspectorGUI();
if (EditorGUI.EndChangeCheck())
I did, however, fix it locally on my end. This is a section of code from Editor/Inspector/VisualEffectEditor.cs source, modified to set GUI.changed = true if modifications were made:
This is the very end of the OnInspectorGUI function:
/// 2022-06-05 - Will
/// Added change flag to capture modified parameters
bool changed = false;
if (!m_VisualEffectAsset.hasMultipleDifferentValues)
{
if (showGeneralCategory)
InitialEventField(resource);
DrawRendererProperties();
/// 2022-06-05 - Will Poillion
/// Modified DrawParameters to return a bool if a parameter was modified.
changed = DrawParameters(resource);
}
EditorGUI.indentLevel = 0;
if (serializedObject.ApplyModifiedProperties())
{
var window = EditorWindow.GetWindow<VFXViewWindow>();
if (window != null)
window.OnVisualEffectComponentChanged(targets.Cast<VisualEffect>());
}
/// 2022-06-05 - Will
/// If changed, then set GUI.changed = true to trigger EndChangeCheck
if (changed)
GUI.changed = true;
And in order for the DrawParameters to returned whether a parameter has been changed or not, this is added to the top of the DrawParameters function:
/// Added changed bool
bool changed = false;
And then at the end set the changed flag if properties were modified:
/// 2022-06-05 - Will
/// If any property modified, then set changed flage
if (m_SingleSerializedObject.ApplyModifiedProperties())
{
changed = true;
GUI.changed = true;
}
}
}
}
}
}
}
GUILayout.Space(1); // Space for the line if the last category is closed.
/// 2022-06-05 - Will
/// Return changed flag
return changed;
}
I was hesitant to call it a bug as I imagine this means of detecting editor changes might be falling out of favor and on the road to being deprecated. However, in the meantime this is the means I’m aware of to detect changes to the exposed properties.
I’m using the latest 12.1.7 version of VFX graph on Unity 2021.3.9f1. I’m attaching the entire VisualEffectEditor.cs to get the fully customized file.
Again, let me know if there’s a more accepted way of doing this. Or if this is truly a bug, then I’m glad I labeled it as such!
Thanks!
Will
8432228–1116650–VisualEffectEditor.cs (71.5 KB)