Been working on my own ‘create asset menu’ that I can customise freely to replace the oversized right-click menu for myself. Nothing exciting as of yet, only looks like this so far:
Though as I was implementing ways to add and remove groups, utilising the SerializedObject/Property API, I would constantly get pinged with these errors:
InvalidOperationException: Collection was modified; enumeration operation may not execute.
System.Collections.Generic.List`1+Enumerator[T].MoveNextRare () (at <c0b7b90d34a54066a7234dad69255116>:0)
System.Collections.Generic.List`1+Enumerator[T].MoveNext () (at <c0b7b90d34a54066a7234dad69255116>:0)
UnityEditor.UIElements.Bindings.SerializedObjectBindingContext.UpdateTrackedProperties () (at <c53c17c8b59b40a8bfdfde8db5a0f019>:0)
UnityEditor.RetainedMode:UpdateSchedulers()
Which would also wipe out some of the data in my ScriptableSingleton config asset.
After a bunch of dicking about, I finally worked out that the cause was the label in each of the group list elements on the side, of which I had bound to the serialized property for the group’s name. Simply assigning it normally solved the issue:
public void BindToGroup(SerializedProperty groupProperty, int index)
{
_groupProperty = groupProperty;
_index = index;
// fine
var group = (CreateAssetWindowGroup)_groupProperty.boxedValue;
_groupNameLabel.text = group.GroupName;
// causes issues
//var nameProperty = _groupProperty.FindPropertyRelative("_groupName");
//_groupNameLabel.BindProperty(nameProperty);
}
(Though weirdly, when editing the group name in the scriptable singleton, the label remains synchronised to the value, so no idea why that still happens).
The weirdest thing is that I do the same thing in another editor window, and this issue doesn’t happen at all. Is this some kind of race condition going on?
I can post the full code if anyone wants to see, though there’s a lot of it.