dbrizov / NaughtyAttributes

Attribute Extensions for Unity
MIT License
4.53k stars 464 forks source link

if I use both Dropdown and OnValueChanged, the OnValueChanged method will execute twice. #319

Open djnjbjb opened 2 years ago

djnjbjb commented 2 years ago

Here is my code:

public enum Mode
{
    Normal,
    Url
}

[NaughtyAttributes.Dropdown( "modeValues" )]
[NaughtyAttributes.OnValueChanged( "OnModeChange" )]
public Mode mode;

NaughtyAttributes.DropdownList<Mode> modeValues()
{
    return new NaughtyAttributes.DropdownList<Mode>() {
        { "Normal",   Mode.Normal },
        { "Url",    Mode.Url },
    };
}

void OnModeChange()
{
    print( mode );
}

I use both Dropdown and OnValueChanged. It appears the method OnModeChange() executes twice.

I'm using Naughty Attributes 2.1.4.

aTTocs commented 1 year ago

This problem is not limited to DropDown. AllowNesting also reproduces it, and I'm guessing most other Naughty Attributes do too.

NaughtyEditorGUI.PropertyField_Implementation calls propertyFieldFunction.Invoke, which eventually calls PropertyDrawerBase.OnGUI, and both call PropertyUtility.CallOnValueChangedCallbacks. Is this intentional?

mrkyee commented 1 year ago

I also noticed this issue.